R - 错误:'rJava' 的 loadNamespace() 中的 .onLoad 失败 [英] R - Error : .onLoad failed in loadNamespace() for 'rJava'

查看:34
本文介绍了R - 错误:'rJava' 的 loadNamespace() 中的 .onLoad 失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在加载 rJava 包时,我收到此错误:

<块引用>

错误:.onLoad 在 loadNamespace() for 'rJava' 中失败,详细信息:调用: inDL(x, as.logical(local), as.logical(now), ...)错误:无法加载共享对象C:/Users/ankitagarwal5/Documents/R/win-library/3.2/rJava/libs/x64/rJava.dll":LoadLibrary 失败:%1 不是有效的 Win32 应用程序.另外: 警告信息:包rJava"是在 R 版本 3.2.3 下构建的错误:rJava"的包或命名空间加载失败

我参考了 StackOverflow 上的各种帖子并尝试进行相应的更改,但没有任何效果.这些是我为解决该问题而遵循的各种步骤:

if (Sys.getenv("JAVA_HOME")!="")Sys.setenv(JAVA_HOME="")图书馆(rJava)

这没用.

然后我尝试了这个:

options(java.home="C:\\Program Files\\Java\\jre1.8.0_91\\")图书馆(rJava)

这也不起作用.

我的 jvm.dll 位于我的 Windows 7 64 位操作系统的这个位置 - C:\Program Files (x86)\Java\jre1.8.0_91\bin\client

我还将 C:\Program Files (x86)\Java\jre1.8.0_91\bin\client 添加到我的环境变量中的 PATH 变量并重新启动 RStudio 并尝试安装和加载 rJava再次.这也不起作用.

如果有人能帮我解决这个问题,我将不胜感激.

谢谢各位!

解决方案

这对我有用 -

通常通过安装适合您使用的 R 版本类型(即 64 位 R 或 32 位 R)的 Java 版本(即 64 位 Java 或 32 位 Java)来解决此错误.此问题很容易影响 Windows 7 用户,因为他们安装的 Java 版本可能与他们使用的 R 版本不同.

注意需要‘手动下载安装’64位版本的JAVA.默认情况下,下载页面给出的是 32 位版本.

您可以从此链接中选择要安装的确切 Java 版本.如果您可能(出于某种原因)在两个版本的 R 上工作,您可以安装两个版本的 Java(安装Java 运行时环境"可能足以满足您的需求).(来源:Uwe Ligges)

其他可能的解决方案是尝试重新安装 rJava.

如果这不起作用,您还可以通过在加载库之前进行设置来手动设置 Java 位置的目录:

Sys.setenv(JAVA_HOME='C:\\Program Files\\Java\\jre7') # 64 位版本Sys.setenv(JAVA_HOME='C:\\Program Files (x86)\\Java\\jre7') # 32 位版本图书馆(rJava)

参考此链接 - http://www.r-bloggers.com/how-to-load-the-rjava-package-after-the-error-java_home-cannot-be-determined-来自注册表/

While loading rJava package, I receive this error:

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/ankitagarwal5/Documents/R/win-library/3.2/rJava/libs/x64/rJava.dll':
  LoadLibrary failure:  %1 is not a valid Win32 application.

In addition: Warning message:
  package ‘rJava’ was built under R version 3.2.3 
Error: package or namespace load failed for ‘rJava’

I referred various posts on StackOverflow and tried to make changes accordingly, but nothing worked. These are the various steps I followed to resolve the issue:

if (Sys.getenv("JAVA_HOME")!="")
  Sys.setenv(JAVA_HOME="")
library(rJava)

This didn't work.

Then I tried this:

options(java.home="C:\\Program Files\\Java\\jre1.8.0_91\\")
library(rJava)

This didn't work either.

My jvm.dll is at this location in my Windows 7 64 bit OS - C:\Program Files (x86)\Java\jre1.8.0_91\bin\client

I also added C:\Program Files (x86)\Java\jre1.8.0_91\bin\client to my PATH variable in my Environment variables and restarted RStudio and tried to install and load rJava again. That also didn't work.

I would really appreciate if someone could please help me resolve this issue.

Thanks guys!

解决方案

This worked for me -

This error is often resolved by installing a Java version (i.e. 64-bit Java or 32-bit Java) that fits to the type of R version that you are using (i.e. 64-bit R or 32-bit R). This problem can easily effect Windows 7 users, since they might have installed a version of Java that is different than the version of R they are using.

Note that it is necessary to ‘manually download and install’ the 64 bit version of JAVA. By default, the download page gives a 32 bit version .

You can pick the exact version of Java you wish to install from this link. If you might (for some reason) work on both versions of R, you can install both version of Java (Installing the "Java Runtime Environment" is probably good enough for your needs). (Source: Uwe Ligges)

Other possible solutions is trying to re-install rJava.

If that doesn’t work, you could also manually set the directory of your Java location by setting it before loading the library:

Sys.setenv(JAVA_HOME='C:\\Program Files\\Java\\jre7') # for 64-bit version
Sys.setenv(JAVA_HOME='C:\\Program Files (x86)\\Java\\jre7') # for 32-bit version
library(rJava)

Refer this link - http://www.r-bloggers.com/how-to-load-the-rjava-package-after-the-error-java_home-cannot-be-determined-from-the-registry/

这篇关于R - 错误:'rJava' 的 loadNamespace() 中的 .onLoad 失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆