Hi I'm trying to import a large csv file without quotes around each field. This creates some problems when there are "#" characters in certain strings as R understands its comment field and ignores the rest of the line. Here's an example: var1, var2, var3, var4 one, two, three, four Use this in R to get off clipboard: read.table("clipboard", header=F, sep=",",na.strings=c("NULL", ""), dec=".", strip.white=TRUE, fill=T) Now try it with this table: var1, var2, var3, var4 one#, two, three, four Notice R ignores everything after the # character. Is this something that can be fixed? -- View this message in context: http://r.789695.n4.nabble.com/read-table-understands-comment-field-and-ignores-text-tp2021036p2021036.html Sent from the R help mailing list archive at Nabble.com.
Marc Schwartz
2010-Apr-22 19:09 UTC
[R] read.table understands comment field and ignores text
On Apr 22, 2010, at 2:05 PM, Jack T. wrote:> > Hi I'm trying to import a large csv file without quotes around each field. > This creates some problems when there are "#" characters in certain strings > as R understands its comment field and ignores the rest of the line. > > Here's an example: > > var1, var2, var3, var4 > one, two, three, four > > Use this in R to get off clipboard: > > read.table("clipboard", header=F, sep=",",na.strings=c("NULL", ""), > dec=".", strip.white=TRUE, fill=T) > > Now try it with this table: > > var1, var2, var3, var4 > one#, two, three, four > > Notice R ignores everything after the # character. Is this something that > can be fixed?Change the 'comment.char' argument to "": read.table(...., comment.char = "") See ?read.table for more information. HTH, Marc Schwartz
David Winsemius
2010-Apr-22 19:11 UTC
[R] read.table understands comment field and ignores text
On Apr 22, 2010, at 3:05 PM, Jack T. wrote:> > Hi I'm trying to import a large csv file without quotes around each > field. > This creates some problems when there are "#" characters in certain > strings > as R understands its comment field and ignores the rest of the line. > > Here's an example: > > var1, var2, var3, var4 > one, two, three, four > > Use this in R to get off clipboard: > > read.table("clipboard", header=F, sep=",",na.strings=c("NULL", ""), > dec=".", strip.white=TRUE, fill=T) > > Now try it with this table: > > var1, var2, var3, var4 > one#, two, three, four > > Notice R ignores everything after the # character. Is this > something that > can be fixed??read.table Read the documentation with particular attention to comment.char --> >David Winsemius, MD West Hartford, CT
Oh man, totally missed that one! Thanks so much for the reminder. -- View this message in context: http://r.789695.n4.nabble.com/read-table-understands-comment-field-and-ignores-text-tp2021036p2021055.html Sent from the R help mailing list archive at Nabble.com.