0

I have the following added to my system path on Windows 10: C:\Program Files\R\R-3.4.3\bin\x64

Then I tried running from cmd prompt ~:> R myscript.R

ARGUMENT 'example_batch.R' ignored

It proceeded to an interactive session without any execution.

No idea how it seemed to work in this answer. I would prefer something this simple, as it is in Python.

The following works R -e "source('myscript.R')"

But I'll never remember this when I need it.

Wassadamo
  • 874
  • 8
  • 19

1 Answers1

0

The best way I've found is by executing Rscript.exe (it's installed with R.exe inside R directory). You can do:

"C:\Program Files\R\R-3.6.0\bin\Rscript.exe" D:\path\to\yourRfile.r arg1 arg2 arg3

The quotation marks ("") are necessary because dir name Program Files has space between it and Windows CMD wouldn't recognize it without quotation marks.

If you don't want to write R path, you can put R Path to your windows PATH environment variable. This way you could run like:

Rscript.exe D:\path\to\yourRfile.r arg1 arg2 arg3

If you have doubts how to add R path to Windows PATH environment variable, you can follow these instructions (they are for adding Java to PATH, but you can use for R, the idea is the same).