R - 我是否需要使用 print() 添加显式换行符? [英] R - do I need to add explicit new line character with print()?

查看:44
本文介绍了R - 我是否需要使用 print() 添加显式换行符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 R 中使用换行符?

How do I use the new line character in R?

myStringVariable <- "Very Nice ! I like";

myStringVariabel <- paste(myStringVariable, "
", sep="");

上面的代码不起作用

P.S 在谷歌搜索这类东西时存在重大挑战,因为查询R 换行符"似乎确实让谷歌感到困惑.我真的希望 R 有一个不同的名字.

P.S There's significant challenges when googling this kind of stuff since the query "R new line character" does seem to confuse google. I really wish R had a different name.

推荐答案

R 的本质意味着当你简单地打印出来时,你永远不会在字符向量中出现换行符.

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
world
")
[1] "hello
world
"

也就是说,换行符在字符串中,它们只是不会被打印为新行.但是,如果要打印它们,可以使用其他函数,例如 :

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

这篇关于R - 我是否需要使用 print() 添加显式换行符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆