我有一个导入java的包“ javaOnLoadFailed”(只是用于测试我的问题的最小包,因此名称很怪异)。即使require(rJava)本身运行正常,当我尝试check()或install()软件包时,也会出现“ rJava”错误。
install()给出以下错误:
> install()
Installing javaOnloadFailed
"C:/Program Files/R/R-3.2.0/bin/x64/R" --no-site-file --no-environ --no-save \
--no-restore CMD INSTALL \
"C:/Projects/stackoverflow/javaOnloadFailed/javaOnLoadFailed" \
--library="C:/Users/adb2018/Documents/R/win-library/3.2" --with-keep.source \
--install-tests
* installing *source* package 'javaOnloadFailed' ...
** R
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
*** arch - i386
Error : .onLoad failed in loadNamespace() for 'rJava', details:
call: inDL(x, as.logical(local), as.logical(now), ...)
error: unable to load shared object 'C:/Users/adb2018/Documents/R/win-library/3.2/rJava/libs/i386/rJava.dll':
LoadLibrary failure: %1 is not a valid Win32 application.
Error: loading failed
Execution halted
*** arch - x64
ERROR: loading failed for 'i386'
* removing 'C:/Users/adb2018/Documents/R/win-library/3.2/javaOnloadFailed'
Error: Command failed (1)
我正在使用带有sessionInfo()的Architect中的R 3.2.0:
R version 3.2.0 (2015-04-16)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1
locale:
[1] LC_COLLATE=English_United States.1252
[2] LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] devtools_1.7.0.9000 rj_2.0.3-2
loaded via a namespace (and not attached):
[1] tools_3.2.0 rj.gd_2.0.0-1
最佳答案
Java环境变量为空
> Sys.getenv('JAVA')
[1] ""
基于suggestion,我尝试将JAVA环境变量设置为指向Java的64位版本(因为我正在运行R 64位,如您从sessionInfo中看到的那样,但这是行不通的:
> Sys.setenv(JAVA_HOME='C:\\Program Files\\Java\\jre1.8.0_45')
> install()
Installing javaOnloadFailed
"C:/Program Files/R/R-3.2.0/bin/x64/R" --no-site-file --no-environ --no-save \
--no-restore CMD INSTALL \
"C:/Projects/stackoverflow/javaOnloadFailed/javaOnLoadFailed" \
--library="C:/Users/adb2018/Documents/R/win-library/3.2" --with-keep.source \
--install-tests
* installing *source* package 'javaOnloadFailed' ...
** R
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
*** arch - i386
Error : .onLoad failed in loadNamespace() for 'rJava', details:
call: inDL(x, as.logical(local), as.logical(now), ...)
error: unable to load shared object 'C:/Users/adb2018/Documents/R/win-library/3.2/rJava/libs/i386/rJava.dll':
LoadLibrary failure: %1 is not a valid Win32 application.
Error: loading failed
Execution halted
*** arch - x64
ERROR: loading failed for 'i386'
* removing 'C:/Users/adb2018/Documents/R/win-library/3.2/javaOnloadFailed'
Error: Command failed (1)
然后,我尝试设置JAVA环境变量,使其指向我系统上Java的32位版本,然后它起作用了!
> Sys.setenv(JAVA_HOME='C:\\Program Files (x86)\\Java\\jre1.8.0_45\\')
> install()
Installing javaOnloadFailed
"C:/Program Files/R/R-3.2.0/bin/x64/R" --no-site-file --no-environ --no-save \
--no-restore CMD INSTALL \
"C:/Projects/stackoverflow/javaOnloadFailed/javaOnLoadFailed" \
--library="C:/Users/adb2018/Documents/R/win-library/3.2" --with-keep.source \
--install-tests
* installing *source* package 'javaOnloadFailed' ...
** R
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
*** arch - i386
*** arch - x64
* DONE (javaOnloadFailed)
[INFO] Updating the R environment index started...
[INFO] The R environment index was updated successfully.
我不太明白为什么我需要指向Java 32位才能使R 64位工作,但这似乎是事实。
顺便说一句,不要偶然发现我的包名“ javaOnLoadFailed”。我只是用该名称创建了一个最小的程序包来测试问题。
关于r - 安装软件包时,.onLoad在“rJava”的loadNamespace()中失败,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29941797/