在R中的print语句中添加换行符

时间:2014-06-06 00:21:35

标签: r

当使用打印功能打印到屏幕时,我希望一行出现在一行上,下一行出现在第二行。

这一行

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

我想要打印

[1]“嘿,我希望这是第一行

[2]如果你能提供帮助,这就是第二行会很棒

1 个答案:

答案 0 :(得分:7)

我假设您的示例输出实际上应该是三行而不是两行...您应该使用cat而不是print,并将sep="\n"添加到paste语句:

 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"))

输出:

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