【问题标题】:Double quotes in Rscript.exe expressions using Powershell使用 Powershell 的 Rscript.exe 表达式中的双引号
【发布时间】:2019-02-01 02:54:58
【问题描述】:

在向 R 发送表达式时,我似乎无法正确地将双引号传递给 Rscript.exe 在 Powershell 中使用“-e”标志。

当我尝试使用标准 Windows 命令行的命令时 ?Rscript 文档:

& 'C:\Program Files\R\R-3.5.2\bin\Rscript.exe' -e "date()" -e "format(Sys.time(), \"%a %b %d %X %Y\")"

返回:

[1] "Thu Jan 31 20:27:53 2019"
Error: unexpected end of input
Execution halted

根据我对 Powershell 字符串的理解,我希望这可以工作:

& 'C:\Program Files\R\R-3.5.2\bin\Rscript.exe' -e 'date()' -e 'format(Sys.time(), "%a %b %d %X %Y")'

但它会返回:

[1] "Thu Jan 31 20:36:02 2019"
Error: unexpected input in "format(Sys.time(), %a"
Execution halted

有谁知道我应该如何格式化这些命令?谢谢!

【问题讨论】:

    标签: r


    【解决方案1】:

    您必须转义 R Powershell 的引号。第一个使用 \",第二个使用双倍的 ""。

    'format(Sys.time(), \""%a %b %d %X %Y\"")'
    

    【讨论】:

    • 运行& 'C:\Program Files\R\R-3.5.2\bin\Rscript.exe' -e "date()" -e 'format(Sys.time(), \""%a %b %d %X %Y\"")'[1] "Thu Jan 31 21:23:07 2019" Error: unexpected SPECIAL in "format(Sys.time(), %a %" Execution halted
    猜你喜欢
    • 2019-01-12
    • 2011-09-15
    • 1970-01-01
    • 1970-01-01
    • 2015-01-22
    • 1970-01-01
    • 2015-06-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多