2

Is there an R equivalent for Environment.NewLine in .NET?

I'm looking for a character object that would represent a new line based on the environment, e.g. CR LF ("\r\n") on Windows and LF ("\n") on Unix. I couldn't find any such thing in the R documentation, or the default R options.

2 Answers 2

2

There’s no equivalent, but most of the time you won’t need it: as long as you’re writing to a text connection, the operating system will do the correct thing and treat '\n' according to the platform’s specification; for example, the documentation of writeLines says:

Normally writeLines is used with a text-mode connection, and the default separator is converted to the normal separator for that platform (LF on Unix/Linux, CRLF on Windows).

Sign up to request clarification or add additional context in comments.

1 Comment

I was initially using write and noticed that it called cat with \n, so I decided to go with writeBin to force \r\n. I guess as long as one sends text to a file, writeLines is fine. Still, too bad there's no equivalent.
0

The \n should still work:

> s = "line 1\nline 2" > cat(s) line 1 line 2 

Here's a separate question which explains that print(s) doesn't quite work when trying to output strings with escape characters, and we should use cat or writeLine instead: Printing newlines with print() in R

1 Comment

Perhaps I should have clarified this in my question; I'm writing data to files using writeBin.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.