Print, cat, paste in R separated by newline character

mynameisJEFF picture mynameisJEFF · Jun 3, 2014 · Viewed 13.9k times · Source

I want to do the print the elements of a vector line by line in R like below

1

2

3

However, when I do paste(c(1,2,3), "\n") or paste(c(1,2,3),sep = "\n"), the new line never gets printed out. The same thing goes for cat as well. I always get the following:

"1" "2" "3"

I would like to know to get around this problem.

Answer

Andrie picture Andrie · Jun 3, 2014

Try:

cat(paste(1:3), sep="\n")
1
2
3