14

In batch script, I can run an R script with the following syntax:

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.

Ross Ridge
  • 38,414
  • 7
  • 81
  • 112
defoo
  • 5,159
  • 11
  • 34
  • 39

2 Answers2

22

You should probably look Rscript instead of redirection -- this would become

Rscript.exe C:\someScript.R

where you can add the usual options.

Dirk Eddelbuettel
  • 360,940
  • 56
  • 644
  • 725
  • 5
    For anyone visiting this page now (and I know it's 5 years old), there's a more general answer for running external programs and redirecting stdin to powershell at http://stackoverflow.com/questions/12478535/how-can-i-execute-an-external-program-with-parameters-in-powershell . Clearly though Rscript is a better option than Rterm for this. – Nick Kennedy Jun 13 '15 at 14:44
4

Easiest way is probably to wrap it in a call to cmd.exe:

cmd.exe /C "Rterm.exe --quiet --slave --vanilla < `"C:\some_script.R`""
James Kolpack
  • 9,331
  • 2
  • 44
  • 59