R script from the command line

I wanted to run this example script: http://mazamascience.com/WorkingWithData/?p=912 from the Windows command line. So I opened the command line and typed Rscript tryCatch.R 1 . However, I continue to receive the error message Error: R not found . I set the PATH environment variable as C:\Programme\R\R-3.0.1\bin . If I just type R.exe , it starts R , but cannot find the packages that should be loaded at startup (for example, package 'utils' in options<"defaultPackages"> was not found ). I assume that I need to specify a different path to the libraries, but I do not know where to do this.

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

+6
source share
3 answers

I found out that the language issue for Windows 7 is similar to that 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 script runs correctly on the command line.

Thanks to everyone who tried to help!

+1
source

Rscript very convenient ( R CMD BATCH is an old way) specially under the windows, but as a rule, under I create a batch file to avoid all the headaches.

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 the console (using cmd), go to where you saved your launcher.bat file and run it. Or from R-cosnol using shell :

 shell('path_to_launcher\launcher.bat') 
+5
source

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

0
source

Source: https://habr.com/ru/post/948205/


All Articles