如何使用R在多行上执行字符串,相当于此Python脚本:
string = """
Because I could
Not stop for Death
He gladly stopped for me
"""
这个的上下文是,我有一个非常长的SQL代码,带有一堆换行符和子命令,我想作为一个字符串输入以便稍后进行评估,并且手动清理它将是困难的。
答案 0 :(得分:5)
不需要特别的东西。只是开头和结尾的引号。
在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
在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'