I've developed a Java application that uses JRI to make use of the ptw package.
On Linux (Ubuntu 10.04, R 2.10.1, JRI 0.5.0) it works fine.
However, on Vista (R 2.12.0, JRI 0.5.0) when the application evaluates "library(ptw)" the following error occurs:
Error in library(ptw) : object 'ptw' not found
When I run R from the Vista command-line and issue the "library(ptw)" command there is no problem.
If I copy the ptw package from my %USERPROFILE%\Documents\R\win-library to %R_HOME%\library then the problem goes away. However, I don't want my users to have to do this, in fact, some might not have permission to do so.
Therefore, how can I get J开发者_开发知识库RI to invoke an R-Engine that has access to packages that the user has installed in their %USERPROFILE%\Documents\R\win-library?
I've also asked on the r-help mailing list but no joy.
I am aware of the libloc parameter for the library() function but I'd prefer something a little less fragile, i.e. automatic rather than requiring configuration...
If the locations are different than the default, they should be mentioned in the Rprofile.site file, where either .libPaths()
is used or the .Library.site
variable is set. Check if you can find that in the Rprofile.site file of your R version, let your application print the output of the function .libPaths()
.
As far as I know (but I can be wrong), JRI uses the Rserve, which doesn't launch R the classic way. I suspect that on a windows this forgets about the Rprofile.site somehow (which would be a bug in fact). Can't see another reason why it wouldn't work, but I'm no expert.
One solution is to :
- source the Rprofile.site in the beginning.
- or add any possible location to the
.libPaths()
(see?.libPaths
) - or set the
.Library.site
variable yourself in the script
You might want to check if the problem persists on Windows 7, because I've noticed problematic behaviour of some programs trying to connect to R when using Vista whereas the same version works fine on Windows 7.
%USERPROFILE%\Documents\R\win-library is a "non-standard" library location, in spite of the fact that it is added to .libPaths() automatically when the user is a non-administrator.
After your JRIEngine has been started, you can add the library location manually.
jriengine.parseAndEval(".libPaths(<the directory>)");
Thanks to the comments of Joris and Ian I found that explicitly setting the R_LIBS_USER environment variable prior to running my application solved the problem.
For whatever reason this is only necessary on Vista (vs. Linux). On both systems the Rprofile.site file is an empty template.
精彩评论