Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Last line of csv file is not read by fread from package data.table with error message 'Discarded single-line footer'

I have a csv file that has windows line endings (CR LF) and is separated by semicolon. The last line in the file is an empty line, i.e. no semicolons contained or any other character.

When reading the file with fread from the data.table package the second last line, i.e. the last data row, is not loaded and the error message says "Discarded single-line footer".

like image 227
Oliver Avatar asked Jan 11 '19 16:01

Oliver


People also ask

Can fread read CSV?

We're able to successfully import the CSV file using the fread() function. Note: We used double backslashes (\\) in the file path to avoid a common import error. Notice that we didn't have to specify the delimiter either since the fread() function automatically detected that it was a comma.

What is the difference between fread and read CSV?

I understand that fread() should be faster than read. csv() because it tries to first read rows into memory as character and then tries to convert them into integer and factor as data types. On the other hand, fread() simply reads everything as character.

What is fread function in R?

Its fread() function is meant to import data from regular delimited files directly into R, without any detours or nonsense. Note that “regular” in this case means that every row of your data needs to have the same number of columns.


1 Answers

Try inserting fill = TRUE.

In my case, inserting fill = true all works correctly.

like image 191
Sab Avatar answered Sep 27 '22 20:09

Sab