安装 ReporteRsjars 时无法加载 rJava.dll - 不是有效的 Win32 应用程序

Unable to load rJava.dll - not a valid Win32 application - while installing ReporteRsjars

我在 64 位 R、64 位 Windows 10 机器上安装 ReporteRsjars 包时遇到问题。 ReporteRsjars 包是从 CRAN 存档(tar.gz 文件)下载并从本地文件夹安装的。

R 说它无法加载 rJava.dll 并且似乎正在寻找 32 位 rJava.dll 文件(错误消息:不是有效的 Win32 应用程序)。我不知道为什么要这样做。

我已经安装了 rJava 包并且调用库 (rJava) 似乎可以毫无问题地加载 rJava 包。

我还安装了 openJDK 版本 11(64 位),这是一个从 http://jdk.java.net/11/ 下载的 zip 文件。没有Windows安装包,所以我直接解压到C:\ProgramFiles\Java,加了几个系统环境变量: C:\Program Files\Java\jdk-11\bin 和 C:\程序Files\Java\jdk-11\bin\server

并创建系统环境变量: JAVA_HOME = C:\程序Files\Java\jdk-11

在 Windows 命令提示符下键入 java -version 确认我的机器有 openJDK 11,OpenJDK 运行时环境 18.9。和 OpenJDK 64 位服务器 18.9。

我不知道哪里出了问题 - 如果您能提供正确安装 ReporteRsjars 的任何提示,我们将不胜感激。

 install.packages("C:/Users/h/Downloads/ReporteRsjars_0.0.4.tar.gz", repos = NULL, type = "source")
'\u\h\Documents'
CMD.EXE was started with the above path as the current directory.
UNC paths are not supported.  Defaulting to Windows directory.
* installing *source* package 'ReporteRsjars' ...
** package 'ReporteRsjars' successfully unpacked and MD5 sums checked
** R
** inst
** byte-compile and prepare package for lazy loading
** help
No man pages found in package  'ReporteRsjars' 
*** installing help indices
** building package indices
** testing if installed package can be loaded
*** arch - i386
Error: package or namespace load failed for 'ReporteRsjars':
 .onLoad failed in loadNamespace() for 'rJava', details:
  call: inDL(x, as.logical(local), as.logical(now), ...)
  error: unable to load shared object 'C:/Program Files/R/R-3.5.1/library/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:/Program Files/R/R-3.5.1/library/ReporteRsjars'
* restoring previous 'C:/Program Files/R/R-3.5.1/library/ReporteRsjars'
In R CMD INSTALL
Warning in install.packages :
  installation of package ‘C:/Users/h/Downloads/ReporteRsjars_0.0.4.tar.gz’ had non-zero exit status

您需要同时安装 32 位和 64 位 java 版本,因为您正在尝试安装 R 32 和 R 64 位版本的软件包。另外我认为 JAVA_HOME 是没有必要的。如果安装已正确完成,您应该不需要任何额外的环境。变量。

我 运行 在我的 PC 上安装几个 JDK(32 位和 64 位)用于开发后遇到这个问题。在 R-Script 中添加这一行为我解决了这个问题:

Sys.setenv(JAVA_HOME="C:/Program Files/Semeru/jdk-8.0.312.7-openj9/jre")

当然路径需要根据你的Java版本来设置。

在Windows中设置环境变量并重启RStudio也解决了rJava.dll问题。