[R] Pesky file encoding problem
Joshua Banta
jbanta at uttyler.edu
Sun Nov 6 18:25:46 CET 2016
Dear everyone,
Please consider the following code, which I am using to make a custom text file. (I need to build the text file line-by-line like this for some idiosyncratic reasons that I will not get into here. But basically the real text file I am making is longer and more complicated than this.)
outfile = "output.arp"
cat('Title="data"', file=outfile, append=FALSE, sep = "\r\n")
cat('DataType=DNA', file=outfile, append=TRUE, sep = "\r\n")
cat('GenotypicData=1', file=outfile, append=TRUE, sep = "\r\n")
cat('GameticPhase=0', file=outfile, append=TRUE, sep = "\r\n")
cat('LocusSeparator=WHITESPACE', file=outfile, append=TRUE, sep = "\r\n")
cat("", file=outfile, append=TRUE, sep = "\r\n")
cat("[Data]", file=outfile, append=TRUE, sep = "\r\n")
cat("[[Samples]]", file=outfile, append=TRUE, sep = “")
Here is my question:
When the output file (output.arp) is opened using TextEdit on a Mac, each line is shown separated by one or more carriage returns, which is what I want. When the output file is opened using Notepad on a PC, each line of text runs into the next with no carriage returns, which is not what I want.
How can I make this text file, or convert it, in such a way that it will open on Notepad on a PC showing each line separated by one or more carriage returns?
I am aware of solutions to this problem using other software as an intermediary, such as TextWrangler, but I would like to accomplish this entirely using r itself.
I would be most appreciative of the full code needed to get the job done.
Thanks very much in advance!
-----------------------------------
Josh Banta, Ph.D
Assistant Professor
Department of Biology and the Center for Environment, Biodiversity and Conservation
The University of Texas at Tyler
Tyler, TX 75799
http://plantevolutionaryecology.org
[[alternative HTML version deleted]]
More information about the R-help
mailing list