The read.csv
function in R is just read.table
with some set defaults: sep=","
, header=TRUE
, fill=TRUE
, and some others.
Also, read.table
looks at the "head" of the file (the first five lines) to determine the number of columns. In the gives_extra_rows.csv
, the lines with the trailing commas are not part of that.
fill=TRUE
could work okay if some of the later rows in a file have fewer columns that rows at the top, but it results in garbage if, as here, later rows have extra columns: those rows get wrapped around and then padded with NA
s.
My conclusion: Don't use read.csv
, and when you use read.table
, don't use fill=TRUE
.