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

Peng Yu pengyu.ut at gmail.com
Tue Sep 22 04:23:06 CEST 2009


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




More information about the R-help mailing list