CMD R

How to run R scripts from the Windows command line (CMD)

R is great for data transformation, modeling, etc. automatization. In my case, I was collecting data and using library RDCOMClient to send summary information to colleges with Microsoft Outlook, but I needed it to do that automatically. It is possible to run R scripts with the help of the Windows command line and later run them automatically with Windows Task Scheduler, but there are a few things you should know.

There are two ways to do that.

The first possible solution that you put in the batch file looks like this.

The second one looks like this.

Remember to use quotation marks when there is space in the file path.

Here is how it goes step by step.

1. Find the path to R.exe or Rscript.exe on your computer. If you try to run R.exe from the command line, you enter an R terminal.

In Rscript.exe case you can see additional usage options.

2. Find the path to R file.

3. Open Notepad and combine paths together (with quotation marks if needed and additional commands “CMD BATCH” if you choose to go with R.exe).

4. Save as file with extension .bat (for example send_email.bat).

5. Run that batch file to execute R script.



0 comments on “How to run R scripts from the Windows command line (CMD)

Leave a Reply

Your email address will not be published. Required fields are marked *