Jens Oehlschlägel
2003-Nov-05 15:57 UTC
[R] How to represent pure linefeeds chr(10) under R for Windows
I need to write out with write.table() a csv file allowing for line feeds (pure chr(10)) as part of character field (not as a line seperator). How can I do that? Best regards Jens Oehlschl?gel --
Prof Brian Ripley
2003-Nov-05 16:24 UTC
[R] How to represent pure linefeeds chr(10) under R for Windows
Use \n in the character string, if I understand you aright, as in foo <-"a\nb" On Wed, 5 Nov 2003, Jens Oehlschl?gel wrote:> > I need to write out with write.table() a csv file allowing for line feeds > (pure chr(10)) as part of character field (not as a line seperator). > > How can I do that?-- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
Jens Oehlschlägel
2003-Nov-05 17:05 UTC
[R] How to represent pure linefeeds chr(10) under R for Windows
Brian, Simon, Thanks for your quick answers. Unfortunately neither \n nor \012 works. Under R for Windows (tried on 1.8.0 and 1.5.1) they are automatically converted to chr(13)+chr(10). I need only chr(10) within my string column, and chr(13)+chr(10) at line ends of the csv file. If it can't be solved within R, I could workaround by substituting all chr(13)+chr(10) into chr(10) after writing the file using a system() call. However, writing the files twice would be ugly and performance reducing (I am writing an interface). Any idea? Best regards Jens Oehlschl?gel --
Thomas Lumley
2003-Nov-05 18:47 UTC
[R] How to represent pure linefeeds chr(10) under R for Windows
On Wed, 5 Nov 2003, Jens [ISO-8859-1] Oehlschl?gel wrote:> > > Brian, Simon, > > Thanks for your quick answers. Unfortunately neither \n nor \012 works. > Under R for Windows (tried on 1.8.0 and 1.5.1) they are automatically converted > to chr(13)+chr(10). >You may have to write as a binary file to get this to work. I would try opening a binary file connection and passing it to write.csv, but that might mess up the real line endings. -thomas
Apparently Analagous Threads
- Summary: How to represent pure linefeeds chr(10) under R for Windows
- basename returns "." not in filename (PR#13958)
- file.rename overwrites existing target (PR#14065)
- Error in substring: invalid multibyte string
- please help with estimation of true correlations andreliabilities