I have seen in several cases that while read.table() is not able to read a tab delimited file (for example the annotation table of a microarray) returning the following error:
Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings, :
line xxx did not have yyy elements
read.csv() works perfectly on the same file with no errors. I think also the speed of read.csv() is also higher than read.table().
Even more: read.table() is doing very crazy reading a file of me. It makes this error while reading line 100, but when I copy and paste lines 90 to 110 just after the head of the same file, it still makes error of line 100+21 (new lines copied at the beginning). If there is any problem with that line, why doesn’t it report that error while reading the pasted line at the beginning? I confirm that read.csv() reads the same file with no error.
Do you have any idea of why read.table() is unable to read the same files that read.csv() works on it? Also is there any reason to use read.table() in any cases?
read.csvis a fairly thin wrapper aroundread.table; I would be quite surprised if you couldn’t exactly replicate the behaviour ofread.csvby supplying the correct arguments toread.table. However, some of those arguments (such as the way that quotation marks or comment characters are handled) could well change the speed and behaviour of the function.In particular, this is the full definition of
read.csv:so as stated it’s just
read.tablewith a particular set of options.As @Chase states in the comments below, the help page for
read.table()says just as much underDetails: