使用Powershell在Rscript.exe表达式中使用双引号

时间:2019-02-01 02:54:58

标签: r

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

当我尝试从Windows的标准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

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

1 个答案:

答案 0 :(得分:0)

您必须转义R Powershell的引号。第一个使用\“,第二个使用”“。

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