Add line break in print statement in R [duplicate]

When using the print function to print to the screen, I would like one line to appear on one line, and the next line to be on a second line.

with this line

print( paste( "hey I want this to be line one", "and this to be line two", "would be great if you could help" )
)

I want this to print

[1] "hey I want this to be line one

[2] and this to be line two would be great if you could help"

1

1 Answer

I assume your sample output should actually be three lines instead of two... You should use cat instead of print, and add sep="\n" to the paste statement:

 cat(paste("hey I want this to be line one", "and this to be line two", "would be great if you could help" ,sep="\n"))

Output:

hey I want this to be line one
and this to be line two
would be great if you could help

You Might Also Like