我想知道如何在 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/