【问题标题】:Nesting more than two types of quotes in R在 R 中嵌套两种以上类型的引号
【发布时间】:2016-05-07 04:52:25
【问题描述】:

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

'first-quote-type1 "first-quote-type2 "second-quote-type2 '第二引号类型1

在开头使用一个引号,在结尾使用一个引号:

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

错误:"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 中工作?

【问题讨论】:

  • 我很好奇:你为什么要这样做?
  • 我想使用基本函数system()直接从R实现一个bash代码。我在这里使用print() 只是为了让问题更清楚。

标签: r syntax quotes double-quotes


【解决方案1】:

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

print("the man said \"hello\"")

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

所以……

cat("the man said \"hello\"") 将返回 the man said "hello"

【讨论】:

  • print("the man said \"hello\"",quote=FALSE),虽然这也将包括一个索引计数器[1]
猜你喜欢
  • 2013-09-08
  • 2012-04-09
  • 1970-01-01
  • 2021-03-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-09-30
  • 2012-04-08
相关资源
最近更新 更多