[R] Working around 256 byte variable names? + trouble opening large file

David Winsemius dwinsemius at comcast.net
Mon Sep 21 22:33:22 CEST 2009


Read in the first few lines with readLines, try to "eyeball" the  
errors and if not successful, then supply them to read.table through a  
textConnection. Remember that single quotes do not match double  
quotes. Also watch out for "smart-quotes". I don't think they match  
anything.

?readLines
?textConnection
?make.names

Also use the count.fields function to identify malformed lines later  
in the file.

-- 
David Winsemius

On Sep 21, 2009, at 4:24 PM, A Singh wrote:

> :)
> Well that does make even more sense.
>
> Is there a way of fixing the unmatched quote problem though?
> I do not have any clue as to how it can be done.
>
> Will remaking the original file, and then re-reading it in help?
>
>
>
> --On 21 September 2009 16:17 -0400 David Winsemius <dwinsemius at comcast.net 
> > wrote:
>
>>
>> On Sep 21, 2009, at 4:04 PM, A Singh wrote:
>>
>>> Dear R users,
>>>
>>> I am trying to read in a file with 105 columns, and when trying to
>>> attach it, get an error as follows:
>>>
>>>> vc1<-read.table("P:\\R\\Everything-I.txt", header=T, sep=" ",
>>>> dec=".",
>>> na.strings=NA, strip.white=T)
>>>> attach(vc1)
>>> Error in attach(vc1) : variable names are limited to 256 bytes
>>>
>>> Is there a way to get around this, and make R accept the given
>>> variable names? Or will I have to shorten them?
>>>
>> It's my guess that you have an unmatched quote in your header   
>> somewhere.
>> The error is reported when the length of a SINGLE variable  name is  
>> over
>> the 256 character limit, and not when the total number of   
>> characters in
>> all of the variable names is over 256. Shirley, you  cannot have a
>> variable name that want to be that long.
>>
>>> Also, when I try to read in a much larger file with 430 columns, I
>>> get the error:
>>>
>>> Error in scan(file, what, nmax, sep, dec, quote, skip, nlines,
>>> na.strings, :
>>> line 397 did not have 431 elements
>>>
>>> Is it that R isn't dealing too well with Excel-converted-to-text
>>> files? Is it a function of file size?
>>
>> R is not the problem. It is capable of "filling".
>>
>>>
>>> I have double-checked the 430 column file and all data seems to be
>>> in place.
>>
>> Again, probably a misplaced quote character.
>>
>> --
>>
>> David Winsemius, MD
>> Heritage Laboratories
>> West Hartford, CT
>>
>
>
>
> ----------------------
> A Singh
> Aditi.Singh at bristol.ac.uk
> School of Biological Sciences
> University of Bristol
>
>
>
>

David Winsemius, MD
Heritage Laboratories
West Hartford, CT




More information about the R-help mailing list