[Rd] [R] can't load rJava in R 2.8.1 on Windows XP

Duncan Murdoch murdoch at stats.uwo.ca
Mon Jan 26 13:04:39 CET 2009

Dieter Menne wrote:
> Duncan Murdoch <murdoch <at> stats.uwo.ca> writes:
>> I don't know what's going wrong on your system.  I added a browser() 
>> call to the .onLoad function in R/windows/FirstLib.R on my system, and I 
>> see it successfully gets JAVA_HOME from the registry.  It gets a number 
>> of other files, then adds these paths to my PATH variable.  I've used 
>> strsplit() to separate them for viewing.
>> [14] "C:\\Program Files\\Java\\jre1.6.0_07\\bin\\client"
>> [15] "C:\\Program Files\\Java\\jre1.6.0_07/bin"
>> [16] "C:\\Program Files\\Java\\jre1.6.0_07/bin/client"
>> [17] "C:\\Program Files\\Java\\jre1.6.0_07/jre/bin/client"
>> I believe LoadLibrary needs paths to be specified with backslashes, so 
>> you might be able to fix things on your system by changing the file.path 
>> calls in that function to use fsep="\\" instead of the default "/".
> Thanks for your help. 
> I think I tracked it down. It has nothing to do with rJava, but
> rather with Sys.getenv(). Looks like this function truncates around 1024
> characters, and my path is very long due to Visual Studio + Delphi
> + SQL Server.
> See the printout below. Note that the last entry should read \\Delphi,
> and that more entries are coming in my system path.
> This also explains why only some people have the problem.
> No workaround found yet. I keep this message here for other people who 
> have the problem, but possibly this is more for R-devel to be continued.

Yes, I've moved this to R-devel.

If this is an R problem, it's in Sys.setenv:  putting a very long string 
and then starting a shell shows the truncated string, but within the 
shell it's possible to set a much longer one.

However, I don't see a fixed buffer size in the internal R code, so this 
looks like a problem in the run-time.  The docs on MSDN say that the 
system maintains separate user environment variables and system 
environment variables, and the system ones are limited to 1024 
characters:  so this could be our problem.  Our _wputenv call may be 
trying to set a system environment variable, and having it truncated.  
(There's also an overall limit of 32767 chars for all environment 
variables, but I'd guess you're hitting the 1024 byte limit.)

The docs also say there's a SetEnvironmentVariable API function as of 
Win2k, which is our minimal platform these days, so maybe switching to 
that would solve the problem.  I'll give it a try, but probably not today.

Duncan Murdoch
> Dieter
>> p = Sys.getenv("PATH")
>> nchar(p) 
> 1019 
>> strsplit(p,";")$PATH[-(1:27)]
> [1] "C:\\Program Files\\Microsoft SQL
> Server\\100\\Tools\\Binn\\VSShell\\Common7\\IDE\\"
> [2] "C:\\Program Files\\MiKTeX 2.7\\miktex\\bin"                           
> [3] "C:\\Users\\Dieter\\Documents\\Delp"
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

More information about the R-devel mailing list