R equivalent for .NET's Environment.NewLine

偶尔善良 提交于 2020-01-15 03:42:23

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!