7

I wanted to run this example script: http://mazamascience.com/WorkingWithData/?p=912 from Windows command line. So I opened the command line and typed Rscript tryCatch.R 1. However, I keep getting the error message Error: R not found. I did set the PATH environment variable as C:\Programme\R\R-3.0.1\bin. If I just type R.exe, it does start R, but it cannot find the packages that are to be loaded at start (e.g. package 'utils' in options<"defaultPackages"> was not found). I guess I have to set another path to the libraries somewhere, but I haven't got any idea where to do this.

UPDATE: After explicitly typing PATH C:\Programme\R\R-3.0.1\bin (rather than just adding this to the value of the environment variable PATH) it seems that R is found. However, a new problem occurs: In normalizePath<path.expand(path), winslash, mustWork>: path[2] = "C:/Programme/R/R-3.0.1/library": Access denied, the same than for the methods library. Then: Calls: .First ... library -> .getRequiredPackages2 -> library -> normalizePath Execution stopped. I'm using Windows 7 and I do have administrator rights.

4
  • Try using R CMD BATCH tryCatch.R 1. You may have to alter the script to accept the command line arguments (if so I will post an full answer but I am curious to know if this works first) Commented Jun 27, 2013 at 10:15
  • @SimonO101 Thanks for your suggestion, but unfortunately I get the same error message (Error: R not found). Commented Jun 27, 2013 at 11:07
  • You might want to look at batchfiles.googlecode.com . Look at R.bat. e.g. R.bat script myscript.R, which is automatic but requires a reasonably standard installation or the RPathSet.bat alternative which is a flexible batch file in which you edit the variables and then run it prior to running R to set up your environment variables. There is a pdf that comes with it that documents it. Commented Jun 27, 2013 at 11:40
  • @G.Grothendieck Thanks for your suggestion, I'll have a look at this! Commented Jun 27, 2013 at 12:06

3 Answers 3

8

Rscript is very handy (R CMD BATCH is the old way to ) specially under windows, But generally under I create a batch file to avoid all path's headache.

For example say launcher.bat:

@echo off
C:
PATH C:\Programme\R\R-3.0.1\bin;%path%
cd PATH_TO_YOUR_RSCRIPT
Rscript tryCatch.R 1
pause

And open a console(using cmd) , go where you have stored your launcher.bat and launch it. Or from the R cosnole using shell:

shell('path_to_launcher\launcher.bat')
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks for your suggestion, that's a good idea. Based on the content of your launcher-file, I've tried to explicitly define the PATH, which brought me one step forward, but still doesn't work properly. Once I'll get this fixed, I will try to run batch files.
@AnjaM I don'understand why do you mean by explicitly defining PATH? What do you have as error.
I've updated my original question and described the new error there. By explicitly defining PATH I mean really writing PATH C:\Programme\R\R-3.0.1\bin in the command line before typing Rscript tryCatch.R 1 (the way you do it in your launcher-file). Previously, I just added the path to the PATH environment variable in Windows and thought this would be enough.
Try first toi execute the script from R using source . Once you get it works, the method should work.
2

I've found out that it was a language-specific problem on Windows 7, similar to what is described here: https://stat.ethz.ch/pipermail/r-help/2011-May/276932.html

After changing PATH to C:\Program Files\R\R-3.0.1\bin the script is properly executed from the command prompt.

Thanks to everyone who tried to help!

1 Comment

thank you! To note we point the PATH variable at the \bin folder rather than directly targeting the .exe file
0

I ran into this problem under windows 7, apparently, when setting environment variables>user variables the path is not added into the PATH, so the user must add this path in system variables > PATH at the end just add the path to your .EXE files and voila.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.