问题
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.
回答1:
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).
回答2:
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
来源:https://stackoverflow.com/questions/46818744/r-equivalent-for-nets-environment-newline