windows 从 Powershell 运行 R 脚本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2582150/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Run R script from Powershell
提问by defoo
In batch script, I can run an R script with the following syntax:
在批处理脚本中,我可以使用以下语法运行 R 脚本:
Rterm.exe --quiet --slave --vanilla < "C:\some_script.R"
However, Powershell seems to have reserved "<" for future expansion. I am wondering if there is a direct way to run R script within another Powershell script.
但是,Powershell 似乎为将来的扩展保留了“<”。我想知道是否有一种直接的方法可以在另一个 Powershell 脚本中运行 R 脚本。
回答by Dirk Eddelbuettel
You should probably look Rscript
instead of redirection -- this would become
您可能应该查看Rscript
而不是重定向——这将变成
Rscript.exe C:\someScript.R
where you can add the usual options.
您可以在其中添加常用选项。
回答by James Kolpack
Easiest way is probably to wrap it in a call to cmd.exe:
最简单的方法可能是将其包装在对 cmd.exe 的调用中:
cmd.exe /C "Rterm.exe --quiet --slave --vanilla < `"C:\some_script.R`""