Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run R script from Powershell

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.

like image 845
defoo Avatar asked Apr 06 '10 01:04

defoo


People also ask

How do I run an R script?

To run an R command, put the cursor on the line of the command and then click the Run button at the top of the file window. Or just press CTRL-Enter.

Can you run R script from command line?

Running R scripts from the command line can be a powerful way to: Automate your R scripts. Integrate R into production. Call R through other tools or systems.

How do I run an R command line in Windows?

Starting R If R has been installed properly, simply entering R on the command line of a terminal should start the program. In Windows, the program is typically specified as the action performed when clicking on an icon. You can also use this method on a *NIX system that has a window manager such as KDE.


2 Answers

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

Rscript.exe C:\someScript.R

where you can add the usual options.

like image 110
Dirk Eddelbuettel Avatar answered Oct 20 '22 12:10

Dirk Eddelbuettel


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`""
like image 21
James Kolpack Avatar answered Oct 20 '22 11:10

James Kolpack