r - 在 R 中嵌套两种以上的引号

标签 r syntax quotes double-quotes

我想知道如何在 R 的同一行中容纳两种以上的引号。假设我想打印:

'first-quote-type1 "first-quote-type2 "second-quote-type2 'sencond-quote-type1

在开头和结尾使用一个引号,我们有:

print("'first-quote-type1 "first-quote-type2 "second-quote-type2 'sencond-quote-type1")

Error: unexpected symbol in "print("'first-quote-type1 "first"

在这种情况下,我尝试按照 Python 的要求包含三重引号:

print(''''first-quote-type1 "first-quote-type2 "second-quote-type2 'sencond-quote-type1''')

print("""'first-quote-type1 "first-quote-type2 "second-quote-type2 'sencond-quote-type1""")

但是,我也遇到了类似的错误。关于如何使此语法在 R 中工作的一些想法?

最佳答案

要在引号中使用引号,您可以使用反斜杠转义引号字符

print("那个人说\"hello\"")

但是,R 中的打印函数总是转义字符。 要不显示转义字符,请改用 cat()

所以...

cat("the man said\"hello\"") 将返回 男人说“你好”

关于r - 在 R 中嵌套两种以上的引号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35084772/

相关文章:

regex - 删除 R 中向量中每个数字的末尾

java - 将带有单引号的字符串从 Java 插入到 Postgresql 中

r - 从 RStudio 运行 pdflatex 时出错 - 更新后无法编译 pdf

matlab - 相当于 R 中的 matlab 'ans'

r - 线性 SVM 和提取权重

DELPHI:如何在循环或案例之外使用 "break"?

vb.net - 即使在 VB.NET 中调用无参数函数时也强制使用括号?

ios - xcode 7 中 UIControlStateEvents 的新语法是什么?

javascript - 在不影响字符串的情况下 trim 空格

bash - Bash 命令中单引号内变量的扩展