如何在R中做多行字符串?

mmy*_*g77 11 r

我如何使用R在多行上执行一个字符串,等效于以下Python脚本:

string = """
  Because I could
  Not stop for Death
  He gladly stopped for me
  """
Run Code Online (Sandbox Code Playgroud)

这样做的上下文是,我有一个很长的SQL代码,带有一堆换行符和子命令,我想将其作为单个字符串输入以便稍后评估,而手工清理起来将很困难。

Gre*_*gor 11

没什么特别的。在开头和结尾处都只是一个引号。

在R中:

x = "Because I could
Not stop for Death
He gladly stopped for me"
x
# [1] "Because I could\nNot stop for Death\nHe gladly stopped for me"

cat(x)
# Because I could
# Not stop for Death
# He gladly stopped for me
Run Code Online (Sandbox Code Playgroud)

在Python中:

>>> string = """
...     Because I could
...     Not stop for Death
...     He gladly stopped for me
... """
>>> string
'\n\tBecause I could\n\tNot stop for Death\n\tHe gladly stopped for me\n'
Run Code Online (Sandbox Code Playgroud)