12

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
  • 37,034
  • 7
  • 72
  • 110
defoo
  • 4,969
  • 11
  • 32
  • 39

2 Answers2

21

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
  • 347,098
  • 55
  • 623
  • 708
  • 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,233
  • 2
  • 42
  • 57