簡體   English   中英

為什么R無法加載共享對象?

[英]Why R is unable to load a shared object?

我試圖在R中使用XLConnect庫。如果我執行

library(XLConnect)

我收到以下錯誤消息:

JAVA_HOME cannot be determined from the Registry

要解決此問題,我首先JAVA_HOME變量:

Sys.setenv(JAVA_HOME='C:/Program Files (x86)/Java/jre1.8.0_65')
library(XLConnect)

看起來它有助於我走得更遠,但后來又遇到了另一個問題:

unable to load shared object 'C:/Program Files/R/R-3.2.2/library/rJava/libs/x64/rJava.dll'

它想知道為什么R無法加載rJava.dll 至少此文件位於R搜索它的文件夾中:

C:\Program Files\R\R-3.2.2\library\rJava\libs\x64

添加

請注意, rJava.dll文件存在,它位於那里,R正在搜索它。 我想問題是32位和64位版本之間不兼容。 我認為因為R抱怨:

% 1 is not a valid Win32 application

好吧,為什么R期望它成為Win32 application`? First, my OS is 64bit, second my Java is also for the 64bit and finally, the `rJava.dll` object is located in the folder with Win32 application`? First, my OS is 64bit, second my Java is also for the 64bit and finally, the `rJava.dll` object is located in the folder with名稱中Win32 application`? First, my OS is 64bit, second my Java is also for the 64bit and finally, the `rJava.dll` object is located in the folder with x64` Win32 application`? First, my OS is 64bit, second my Java is also for the 64bit and finally, the `rJava.dll` object is located in the folder with中(因此,我認為它也是64位版本)。

我遇到了同樣的問題。 請找到jvm.dll應該在(您的JRE版本可能會有所不同)

C:\Program Files (x86)\Java\jre1.8.0_65\bin\client

要么

C:\Program Files (x86)\Java\jre1.8.0_65\bin\server

將此路徑添加到您的Windows系統路徑並且您很高興。但請記住jre和R的版本應該是一致的,如果您的Java在Program Files它的64位,那么如果它在Program Files (x86)64 bit R啟動Program Files (x86)其32位所以使用32 bit R

就像在我的情況下它顯示64位錯誤 在此輸入圖像描述

但在32位工作完美 在此輸入圖像描述

您確實使用/而不是\\

Sys.setenv(JAVA_HOME='C:\\Program Files (x86)\\Java\\jre1.8.0_65') 
library(XLConnect)

我正在使用UNIX。 因此我不能自己測試它,但你的路徑也可能是錯的。

根據這篇文章,您可以使用以下方法進行搜索:

find.java <- function() {
    for (root in c("HLM", "HCU")) for (key in c("Software\\JavaSoft\\Java Runtime Environment", 
        "Software\\JavaSoft\\Java Development Kit")) {
        hive <- try(utils::readRegistry(key, root, 2), 
          silent = TRUE)
        if (!inherits(hive, "try-error")) 
          return(hive)
    }
    hive
}

感謝@nograpes的功能和本文幫助我給你答案。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM