4

I know there are a lot of questions regarding this issue but I've tried everything and I think I just don't understand how the command line works in windows. I have a file saved in a folder on my desktop, let's say:

C:\Users\abika_000\Desktop\R models\myfile.R

Here is the directory to my R/bin or Rscript/bin:

C:\Program Files\R\R-3.1.0\bin

I want to run this code using the cmd prompt. How would I go about doing this?

I've tried this solution from the question below but I just keep getting errors no matter what I do:

Run R script from command line

What I entered:

> R CMD BATCH C:\Users\abika_000\Desktop\R models\myfile.R
> Rscript C:\Users\abika_000\Desktop\R models\myfile.R

The errors I get are:

'R' is not recognized as an internal or external command, operable program or batch file
'Rscript' is not recognized as an internal or external command, operable program or batch file

EDIT::

Credit to splendour and Phil. I wound up fixing it by entering:

> "C:\Program Files\R\R-3.1.0\bin\"R CMD BATCH "C:\Users\abika_000\Desktop\R models\myfile.R"

I apologize for the poor question. I just wasn't sure how to use the cmd prompt /directories in trying to use R CMD BATCH or Rscript

4
  • What errors are you getting? Commented Dec 5, 2014 at 19:50
  • Usually you would use R CMD BATCH \path\to\script\script.R. What have you tried, and what errors do you see? Commented Dec 5, 2014 at 19:50
  • edited question with trials and errors. most of what i've tried is useless and simply not what cmd line is looking for Commented Dec 5, 2014 at 20:00
  • 3
    You need to add the R/bin folder to your Path environment variable. Commented Dec 5, 2014 at 20:02

2 Answers 2

2

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
Sign up to request clarification or add additional context in comments.

Comments

2

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).

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.