[R] Weird read.table error? (line `n' did not have `m' elements)

Gabor Grothendieck ggrothendieck at gmail.com
Tue Sep 22 04:34:09 CEST 2009


Its highly unusual to use xls as the extension for a text file.
Use something more suggestive.

print out the line in question.  For example, note that scan
and read.table have different defaults for the comment character,
namely, none and #.

On Mon, Sep 21, 2009 at 10:23 PM, Peng Yu <pengyu.ut at gmail.com> wrote:
> On Mon, Sep 21, 2009 at 9:12 PM, Peng Yu <pengyu.ut at gmail.com> wrote:
>> Hi,
>>
>> I have the following commands. It says line 5205 does not have 22
>> elements. But I use my 'vim' checked that line in the file. It has 22
>> fields. Can somebody let me know how to further debug this case?
>>
>> Regards,
>> Peng
>>
>>> annotation = read.table("../EC_results/Juan_15wks_gene_core.xls", header=T, sep='\t',quote='')
>> Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings,  :
>>  line 5204 did not have 22 elements
>>> annotation = count.fields("../EC_results/Juan_15wks_gene_core.xls", sep='\t',quote='')
>>> which(annotation!=22)
>> [1] 5205
>>
>
>
> I also run the following command to test, which confirms that line
> 5205 has 22 elements. Is it a bug in read.table?
>
>> scanned_file = scan("../EC_results/Juan_15wks_gene_core.xls", what=character(),sep='\n',quote='')
> Read 23333 items
>> length(strsplit(scanned_file[5205],'\t')[[1]])
> [1] 22
>
> Regards,
> Peng
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>




More information about the R-help mailing list