Incomplete final line when trying to read csv in R

2019-07-20 01:20发布

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.

2条回答
男人必须洒脱
2楼-- · 2019-07-20 01:38

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.

查看更多
太酷不给撩
3楼-- · 2019-07-20 01:48

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.

查看更多
登录 后发表回答