[R] Embedded carriage returns in text document
Colleagues, I am using R 2.4.0 on both a Mac (10.4.8) and Linux (RedHat 9). To read data from an Excel spreadsheet, I do "save as" in Excel, then select the "Text (tab-delimited)" format. The resulting file uses a tab separator and I can usually read the file using read.delim. Sometimes, the header row contains embedded carriage returns. When I view the file, these carriage returns appear as "^M". Now the problem: When I read.delim these files, they do not read correctly. Sometimes I get error messages; sometimes only the first line is read. Interestingly, invoking the option skip=1 (or a larger N) does not appear to bypass the problem. I can solve the problem by manually deleting these carriage returns either in the original Excel file or the .txt version. However, this is not an ideal solution. Does anyone have a work-around within R? Dennis Dennis Fisher MD P < (The "P Less Than" Company) Phone: 1-866-PLessThan (1-866-753-7784) Fax: 1-415-564-2220 www.PLessThan.com [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch 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.
Re: [R] Embedded carriage returns in text document
Dennis Fisher <[EMAIL PROTECTED]> writes: > Colleagues, > > I am using R 2.4.0 on both a Mac (10.4.8) and Linux (RedHat 9). To > read data from an Excel spreadsheet, I do "save as" in Excel, then > select the "Text (tab-delimited)" format. The resulting file uses a > tab separator and I can usually read the file using read.delim. > > Sometimes, the header row contains embedded carriage returns. When I > view the file, these carriage returns appear as "^M". > > Now the problem: > When I read.delim these files, they do not read correctly. Sometimes > I get error messages; sometimes only the first line is read. > Interestingly, invoking the option skip=1 (or a larger N) does not > appear to bypass the problem. > > I can solve the problem by manually deleting these carriage returns > either in the original Excel file or the .txt version. However, > this is not an ideal solution. > > Does anyone have a work-around within R? Hmm,... I suppose that CR messes with what R or the system thinks is the line-end character in this particular file. My first idea would be to read from a pipe() which executed sed 's/\r//' myfile.dat or something in that vein. Beware of quoting and differences in sed versions -- O__ Peter Dalgaard Ă˜ster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907 __ R-help@stat.math.ethz.ch 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.
Re: [R] Embedded carriage returns in text document
Dennis, You can get rid of the '^M' by reformating the file from DOS to UNIX. Withing a UNIX system send the command > dos2unix filename1 filename2. Filename2 won't have the '^M'. Hope it helps, Augusto Augusto Sanabria. MSc, PhD. Mathematical Modeller Risk Research Group Geospatial & Earth Monitoring Division Geoscience Australia (www.ga.gov.au) Cnr. Jerrabomberra Av. & Hindmarsh Dr. Symonston ACT 2601 Ph. (02) 6249-9155 -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Dennis Fisher Sent: Tuesday, 14 November 2006 9:06 To: r-help@stat.math.ethz.ch Subject: [R] Embedded carriage returns in text document Colleagues, I am using R 2.4.0 on both a Mac (10.4.8) and Linux (RedHat 9). To read data from an Excel spreadsheet, I do "save as" in Excel, then select the "Text (tab-delimited)" format. The resulting file uses a tab separator and I can usually read the file using read.delim. Sometimes, the header row contains embedded carriage returns. When I view the file, these carriage returns appear as "^M". Now the problem: When I read.delim these files, they do not read correctly. Sometimes I get error messages; sometimes only the first line is read. Interestingly, invoking the option skip=1 (or a larger N) does not appear to bypass the problem. I can solve the problem by manually deleting these carriage returns either in the original Excel file or the .txt version. However, this is not an ideal solution. Does anyone have a work-around within R? Dennis Dennis Fisher MD P < (The "P Less Than" Company) Phone: 1-866-PLessThan (1-866-753-7784) Fax: 1-415-564-2220 www.PLessThan.com [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch 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. __ R-help@stat.math.ethz.ch 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.
Re: [R] Embedded carriage returns in text document
For OS X, http://dos2unix.darwinports.com/ -- Jeffrey R. Spies http://www.nd.edu/~jspies/ On Nov 13, 2006, at 11:06 PM, <[EMAIL PROTECTED]> <[EMAIL PROTECTED]> wrote: > Dennis, > > You can get rid of the '^M' by reformating the > file from DOS to UNIX. Withing a UNIX system > send the command >> dos2unix filename1 filename2. > Filename2 won't have the '^M'. > > Hope it helps, > > Augusto > > > > Augusto Sanabria. MSc, PhD. > Mathematical Modeller > Risk Research Group > Geospatial & Earth Monitoring Division > Geoscience Australia (www.ga.gov.au) > Cnr. Jerrabomberra Av. & Hindmarsh Dr. > Symonston ACT 2601 > Ph. (02) 6249-9155 > > > > > > > -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of Dennis Fisher > Sent: Tuesday, 14 November 2006 9:06 > To: r-help@stat.math.ethz.ch > Subject: [R] Embedded carriage returns in text document > > > Colleagues, > > I am using R 2.4.0 on both a Mac (10.4.8) and Linux (RedHat 9). To > read data from an Excel spreadsheet, I do "save as" in Excel, then > select the "Text (tab-delimited)" format. The resulting file uses a > tab separator and I can usually read the file using read.delim. > > Sometimes, the header row contains embedded carriage returns. When I > view the file, these carriage returns appear as "^M". > > Now the problem: > When I read.delim these files, they do not read correctly. Sometimes > I get error messages; sometimes only the first line is read. > Interestingly, invoking the option skip=1 (or a larger N) does not > appear to bypass the problem. > > I can solve the problem by manually deleting these carriage returns > either in the original Excel file or the .txt version. However, > this is not an ideal solution. > > Does anyone have a work-around within R? > > Dennis > > > Dennis Fisher MD > P < (The "P Less Than" Company) > Phone: 1-866-PLessThan (1-866-753-7784) > Fax: 1-415-564-2220 > www.PLessThan.com > > > [[alternative HTML version deleted]] > > __ > R-help@stat.math.ethz.ch 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. > > __ > R-help@stat.math.ethz.ch 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. [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch 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.