3

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.

Community
  • 1
  • 1
user1751735
  • 31
  • 1
  • 2
  • This happens to me sporadically, and I have no idea why - it is a quirk of MS Excel, somehow not creating the .csv file correctly. Sometimes restarting Excel helps. – Drew Steen Oct 17 '12 at 02:19
  • It will help if you can post an actual problem file, e.g. on Dropbox. – Drew Steen Oct 17 '12 at 02:52
  • Actually, I'd be much more cautious. R doesn't tell you what it's importing, you have to tell it. I'd double check all your columns to ensure they match your expected type (int, numeric, character, factor). \ – Brandon Bertelsen Oct 17 '12 at 03:03
  • 1
    There has to be one blank line at the end. In your `test.csv`, hit enter after `2,2` once you open it in a text editor. hit save and do a `read.csv` on it. No errors, right? – Maiasaura Oct 17 '12 at 04:37
  • 1
    Excel "helpfully" has varying defaults for the EOL character (nothing, CR/LF, etc), so it can creat ".csv" files which are slightly different. As DWin points out, it's just a warning, and will not cause problems – Carl Witthoft Oct 17 '12 at 11:53

2 Answers2

4

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.

IRTFM
  • 258,963
  • 21
  • 364
  • 487
  • @Maiasuara , yes that actually seemed to work! if i did it in excel, it was still giving me issues, but if i do it in a text editor, it seems to work... guess i'll just be doing that before I read anything into R, just to be sure it's being read in correctly... Thanks all! – user1751735 Oct 18 '12 at 17:59
0

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.

chopper
  • 6,649
  • 7
  • 36
  • 53