R-我需要使用print()添加明确的换行符吗? [英] R - do I need to add explicit new line character with print()?

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

问题描述

如何在R中使用换行符?

How do I use the new line character in R?

myStringVariable <- "Very Nice ! I like";

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

上面的代码不起作用

P.S谷歌搜索这类东西时面临着巨大的挑战,因为查询"R新行字符"似乎确实使Google感到困惑.我真的希望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\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

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

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