samedi 19 avril 2014

Appelez R de java - version différente de R - Stack Overflow


On the computers (running fedora) at my work R-2.15 is installed by default. I downloaded R-3.0.2 because I need several packages which are only available for R 3.


When i try to call an Rscript from java using Runtime.getRuntime().exec(command); with command being the String Array {"/path/to/Rscript/3-0" "name/of/script" "...args..."} I get the error WARNING: ignoring environment value of R_HOME and it says that it couldn't load the needed packages. When i run the very same command in a terminal it works well.


What is the difference between the call via java and the call on the console. And how can I fix it?


EDIT 1: when i run my locally installed R-3 version, libPaths returns


> .libPaths()
[1] "/home/<homedir>/.bin/R-3.0.2/library"

But when i call an Rscript from Java, libPaths returns


[1] "/home/<homedir>/R/x86_64-redhat-linux-gnu-library/2.15"
[2] "/usr/lib64/R/library"
[3] "/usr/share/R/library"
[4] "/home/<homedir>/.bin/R-3.0.2/library"

The problem seems to be that Java adds any environment variables that tell R to load packages from the 2.15 installation. How can i prevent this?


EDIT 2: When i list all environment variables using the System.getenv(); method nothing R-related is shown, the same is the case when i list the environment variables using printenv in the terminal. But when i call Sys.getenv in R the variables R_HOME, R_LIBS, ... are defined. How are these defined?




You can choose the library to look in when you load the package. For example, when calling the script via Rscript, you could use


library(rJava, lib.loc = .libPaths()[4])


On the computers (running fedora) at my work R-2.15 is installed by default. I downloaded R-3.0.2 because I need several packages which are only available for R 3.


When i try to call an Rscript from java using Runtime.getRuntime().exec(command); with command being the String Array {"/path/to/Rscript/3-0" "name/of/script" "...args..."} I get the error WARNING: ignoring environment value of R_HOME and it says that it couldn't load the needed packages. When i run the very same command in a terminal it works well.


What is the difference between the call via java and the call on the console. And how can I fix it?


EDIT 1: when i run my locally installed R-3 version, libPaths returns


> .libPaths()
[1] "/home/<homedir>/.bin/R-3.0.2/library"

But when i call an Rscript from Java, libPaths returns


[1] "/home/<homedir>/R/x86_64-redhat-linux-gnu-library/2.15"
[2] "/usr/lib64/R/library"
[3] "/usr/share/R/library"
[4] "/home/<homedir>/.bin/R-3.0.2/library"

The problem seems to be that Java adds any environment variables that tell R to load packages from the 2.15 installation. How can i prevent this?


EDIT 2: When i list all environment variables using the System.getenv(); method nothing R-related is shown, the same is the case when i list the environment variables using printenv in the terminal. But when i call Sys.getenv in R the variables R_HOME, R_LIBS, ... are defined. How are these defined?



You can choose the library to look in when you load the package. For example, when calling the script via Rscript, you could use


library(rJava, lib.loc = .libPaths()[4])

0 commentaires:

Enregistrer un commentaire