R - do I need to add explicit new line character with print()?
Solution 1:
The nature of R means that you're never going to have a newline in a character vector when you simply print it out.
> print("hello\nworld\n")
[1] "hello\nworld\n"
That is, the newlines are in the string, they just don't get printed as new lines. However, you can use other functions if you want to print them, such as cat:
> cat("hello\nworld\n")
hello
world
Solution 2:
You can also use writeLines
.
> writeLines("hello\nworld")
hello
world
And also:
> writeLines(c("hello","world"))
hello
world