How to run an R script file from the command line

廉价感情. 提交于 2019-12-06 06:23:20

I think step 1, if you haven't already done it, is to use a UNIX-y shell emulator, such as Cygwin. Then, assuming it's available on Windows (as it is on Linux/OSX), you can use the wrapper program Rscript.

Or, if you have a UNIX-y shell emulator, you can always pipe input straight into R, e.g.:

R --no-save --no-restore < your_script.R

The executables for R have not been added to your environmental variable PATH. The error you are receiving is CMD complaining that it cannot recognize R as an executable. Both R and Rscript exists under Windows.

From the CMD, write

echo %PATH%

Did you see the path where R is install there? Probably not.

Where is R installed? I'm guessing something like C:\Program Files (x64)\R\R-3.1.2

Follow this link for adding a path to PATH: http://www.computerhope.com/issues/ch000549.htm

The path you want to add is not the location where R is installed, but a subdir. Either add C:\Program Files (x64)\R\R-3.1.2\bin or C:\Program Files (x64)\R\R-3.1.2\bin\x64.

Restart a command prompt, and try to start R from the command line (just type R).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!