Dear Colleagues, Occasionally I deal with computer-generated (i.e., websurvey) data files that haven't quite worked correctly. When I try to read the data into R, I get something like this: Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings, : line 26 did not have 648 elements ...is there any way to get R to tell me how many elements line 26 *did* have? That information would take this error message from frustrating to useful. :) In the specific case today, it DID have 648 elements (produced using perl splitting on the sep="\t" I had passed to read.table), but R was thrown off by the fact that line 26 contained \xD characters when the newline for the file was supposed to be just \n...because there was a text input field into which respondants had put carriage returns. The web survey software was smart enough to encode these differently than it encoded newlines, but this threw R off somehow. Also, there doesn't appear to be a way to specify what a newline should look like in ?read.table, so I just manually went through the data file and replaced \xD with ' '...perhaps read.table should allow for newline specification? -- Adam D. I. Kramer Ph.D. Candidate, Social and Personality Psychology adik at uoregon.edu
On Sat, Jun 6, 2009 at 5:02 PM, Adam D. I. Kramer<adik at ilovebacon.org> wrote:> Dear Colleagues, > > ? ? ? ?Occasionally I deal with computer-generated (i.e., websurvey) data > files that haven't quite worked correctly. When I try to read the data into > R, I get something like this: > > Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings, > : > ?line 26 did not have 648 elements > > ...is there any way to get R to tell me how many elements line 26 *did* > have? That information would take this error message from frustrating to > useful. ?:)?count.fields Hadley -- had.co.nz
On 06/06/09 15:02, Adam D. I. Kramer wrote:> Dear Colleagues, > > Occasionally I deal with computer-generated (i.e., websurvey) data > files that haven't quite worked correctly. When I try to read the data into > R, I get something like this: > > Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings, > : > line 26 did not have 648 elements > > ...is there any way to get R to tell me how many elements line 26 *did* > have? That information would take this error message from frustrating to > useful. :)count.fields() More generally, you might be interested in our approach to integrating data collection on the Web, using JavaScript, with R. See promberger.info (which says "private" but Google finds it pretty fast) finzi.psych.upenn.edu/~baron/ex/template.htm finzi.psych.upenn.edu/~baron/ex/template.html finzi.psych.upenn.edu/~baron/R/template.R finzi.psych.upenn.edu/~baron/R/TRIM.R The last makes a nice data file out of the JavaScript output (which is designed more to be readable at the moment than to be useful). It uses count.fields as a check. None of this stuff is ready for prime time. In my case, there is a 14-year history, with various baggage left over from earlier travels. Jon -- Jonathan Baron, Professor of Psychology, University of Pennsylvania Home page: sas.upenn.edu/~baron