我有一个包" javaOnLoadFailed" (只是用于测试我的问题的最小包,因此奇怪的名称)导入rJava。我得到了' rJava'当我尝试check()或install()包时出错,即使require(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)
我在Architect中使用R 3.2.0,使用sessionInfo():
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
答案 0 :(得分:24)
Java环境变量为空
> Sys.getenv('JAVA')
[1] ""
基于suggestion,我尝试将JAVA环境变量设置为指向64位版本的Java(因为我正在运行R 64位,正如您可以从sessionInfo中看到的那样,但是它没有&#39工作:
> 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环境变量,使其指向我系统上的32位版本的Java,然后它就可以了!
> 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"。我刚刚创建了一个带有该名称的最小包来测试问题。
答案 1 :(得分:2)
许多软件包因安装失败而无法在i386平台上运行,但标准安装过程会尝试这样做。用户在jvm.dll和PATH以及JAVA_HOME上浪费了大量时间,当真正的修复是强制安装时忘记i386。使用install.packages选项。 (这在使用drat库时也有效。(归功于Dason)
install.packages("SqlRender",INSTALL_opts="--no-multiarch")
答案 2 :(得分:1)
记住问题是R不知道jvm.dll在哪里。设置JAVA_HOME时,请使用包含dll文件的目录的路径。
您可以在bin\client
或bin\server
中找到它。
然后该命令变为:
Sys.setenv(JAVA_HOME='C:\\Program Files\\Java\\jre1.8.0_45\\bin\\client')
答案 3 :(得分:1)
我尝试删除JAVA_HOME
系统变量,它可以工作。这样,当您启动R时,Sys.getenv("JAVA_HOME")
会给您""
。
答案 4 :(得分:1)
尝试安装仅在Github中可用的软件包时,我发现了相同的问题。
这为我解决了:
devtools::install_github("snowflakedb/dplyr-snowflakedb", INSTALL_opts=c("--no-multiarch"))