尝试在R中读取csv时最后一行不完整 [英] Incomplete final line when trying to read csv in R

查看:856
本文介绍了尝试在R中读取csv时最后一行不完整的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Mac OS 10.8.2上运行了R v.2.15.1.今天早些时候,每次我尝试导入任何最近创建的(今天)csv文件时,R都会向我抛出错误.较早(今天之前)的csv文件可以正常工作,但是我创建的任何新文件都不会发出警告.

我以相同的方式创建csv-在MS Excel(Office for Mac 2011)中将电子表格另存为.csv.

即使有一个伪文件('test.csv'),我也能得到: 警告信息: 在read.table(file = file,header = header,sep = sep,quote = quote,: readTableHeader在"test.csv"上发现不完整的最后一行"

在TextEdit中,test.csv是:

cat,stuff
1,1
2,2

我尝试在每行的结尾处按回车键(如此处的建议:

我已经重新安装了R和Microsoft Excel.奇怪的是,我能够在没有R的Windows机器上读取csv文件,而不会发出警告.

我知道这只是警告",但是这让我有些紧张,并且似乎有可能在将来引起问题.

没有理由担心. R的读取函数期望"有一个空行,但它们不会导致格式错误的数据帧.

I've got R v.2.15.1 running on Mac OS 10.8.2 . Earlier today, R started throwing errors at me every time I try to import ANY recently created (today) csv files. Older (before today) csv files work fine, but anything I create that's new will not read in without a warning.

I'm creating the csv's the same way -- saving the spreadsheet as .csv in MS Excel (Office for Mac 2011).

Even with a dummy file ('test.csv'), I get this: "Warning message: In read.table(file = file, header = header, sep = sep, quote = quote, : incomplete final line found by readTableHeader on 'test.csv'"

in TextEdit, test.csv is:

cat,stuff
1,1
2,2

I have tried hitting enter at the end of every line (as suggested here: 'Incomplete final line' warning when trying to read a .csv file into R ) , but this doesn't work.

I've re-installed R and Microsoft Excel. Weirdly, I was able to read in the csv file without a warning on a Windows machine with R. On another Mac with R and also with RStudio, I get the same warning...

I know this is "just" a warning, but it makes me a bit nervous and seems to have the potential to cause problems in the future.

解决方案

There is no basis for worry. R's read functions are "expecting" to have an empty line but they are not resulting in malformed dataframes.

这篇关于尝试在R中读取csv时最后一行不完整的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆