Incomplete final line when trying to read csv in R

你离开我真会死。 提交于 2019-12-12 13:18:38

问题


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.


回答1:


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.




回答2:


I ran into this exact problem, and in my case, the data frame I got was malformed. I found that saving an Excel file as UTF-16 and then invoking read.table(... fileEncoding='UTF-16') worked perfectly. No processing required after exporting UTF file from Excel.



来源:https://stackoverflow.com/questions/12925968/incomplete-final-line-when-trying-to-read-csv-in-r

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!