A Singh
2009-Sep-21 20:04 UTC
[R] Working around 256 byte variable names? + trouble opening large file
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? 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? I have double-checked the 430 column file and all data seems to be in place. Thanks for your help! Aditi ---------------------- A Singh Aditi.Singh at bristol.ac.uk School of Biological Sciences University of Bristol
John Kane
2009-Sep-21 20:11 UTC
[R] Working around 256 byte variable names? + trouble opening large file
Well the first suspicious thing seems to be the 256 byte variable names. Do you really have a 256 byte variable name? If so, why? It sounds like R is reading the entire header line as one variable. Why not try exporting the Exce file as a csv file and loading that? --- On Mon, 9/21/09, A Singh <Aditi.Singh at bristol.ac.uk> wrote:> From: A Singh <Aditi.Singh at bristol.ac.uk> > Subject: [R] Working around 256 byte variable names? + trouble opening large file > To: r-help at r-project.org > Received: Monday, September 21, 2009, 4:04 PM > 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? > > > 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? > > I have double-checked the 430 column file and all data > seems to be in place. > > > Thanks for your help! > > Aditi > > > > > ---------------------- > A Singh > Aditi.Singh at bristol.ac.uk > School of Biological Sciences > University of Bristol > > ______________________________________________ > 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. >
David Winsemius
2009-Sep-21 20:17 UTC
[R] Working around 256 byte variable names? + trouble opening large file
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
Steve Lianoglou
2009-Sep-21 20:20 UTC
[R] Working around 256 byte variable names? + trouble opening large file
Hi Aditi, 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?1. Don't use `attach`. Here's a good starting point to help you develop your R coding style, I'm sending you straight to the section about using "attach" :-) http://google-styleguide.googlecode.com/svn/trunk/google-r-style.html#attach 2. what do you get when you run "names(vc1)"?> 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?It's not a function of file size, but rather due to the fact that line 397 does not have as many data entries as the other lines .. maybe this is a function of how excel is exporting the data?> I have double-checked the 430 column file and all data seems to be > in place.How did you check the column to verify that? In Excel? I'm not an excel guru, so I don't know how it handles data export when certain cells are missing in a row -- each row should have as many demarcated data points as any other. So if its a CSV, there should be just as many ","'s in line 397 as there are in the preceding lines. HTH, -steve -- Steve Lianoglou Graduate Student: Computational Systems Biology | Memorial Sloan-Kettering Cancer Center | Weill Medical College of Cornell University Contact Info: http://cbio.mskcc.org/~lianos/contact
hadley wickham
2009-Sep-21 20:22 UTC
[R] Working around 256 byte variable names? + trouble opening large file
On Mon, Sep 21, 2009 at 3:04 PM, A Singh <Aditi.Singh at bristol.ac.uk> 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?Don't use attach? Hadley -- http://had.co.nz/
Possibly Parallel Threads
- Error: length(f1) == length(f2) is not TRUE
- lapply() not converting columns to factors (no error message)
- Printing 'k' levels of factors 'n' times each, but 'n' is unequal for all levels ?
- Splitting massive output into multiple text files
- Differing Variable Length Inconsistencies in Random Effects/Regression Models