R:软件包安装需要“Java SE开发工具包11”?

eanckbw9  于 2023-02-07  发布在  Java
关注(0)|答案(1)|浏览(112)

我尝试按照教程在这里:https://cran.r-project.org/web/packages/r5r/vignettes/intro_to_r5r.html

options(java.parameters = '-Xmx2G')
install.packages('r5r')

library(r5r)
library(sf)
library(data.table)
library(ggplot2)
library(mapview)
mapviewOptions(platform = 'leafgl')

data_path <- system.file("extdata/poa", package = "r5r")
poi <- fread(file.path(data_path, "poa_points_of_interest.csv"))
points <- fread(file.path(data_path, "poa_hexgrid.csv"))
points <- points[ c(sample(1:nrow(points), 10, replace=TRUE)), ]

一切似乎都工作到这里(我不得不安装一个64位版本的Java)-下面的行产生一个错误:

r5r_core <- setup_r5(data_path = data_path, verbose = FALSE)

Error in setup_r5(data_path = data_path, verbose = FALSE) : 
  This package requires the Java SE Development Kit 11.
Please update your Java installation. The jdk 11 can be downloaded from either:
  - openjdk: https://jdk.java.net/java-se-ri/11
  - oracle: https://www.oracle.com/java/technologies/javase-jdk11-downloads.html

我已经按照说明从这个网站https://jdk.java.net/java-se-ri/11下载了更新:

但我仍然得到同样的错误。
我咨询了这个网站(https://rdrr.io/cran/installr/man/install.java.html),并尝试以不同的方式安装这个:

library(installr)

# does the "path" argument in install.jdk() need to be changed?

> install.jdk(
version = 11,
page_with_download_url = "http://jdk.java.net/java-se-ri/",
path = "C:/java")

trying URL 'https://download.java.net/openjdk/jdk11/ri/openjdk-11+28_windows-x64_bin.zip'
Content type 'application/zip' length 187396683 bytes (178.7 MB)
downloaded 178.7 MB

但是当我尝试运行代码时,同样的错误仍然存在:

r5r_core <- setup_r5(data_path = data_path, verbose = FALSE)

Error in setup_r5(data_path = data_path, verbose = FALSE) : 
  This package requires the Java SE Development Kit 11.
Please update your Java installation. The jdk 11 can be downloaded from either:
  - openjdk: https://jdk.java.net/java-se-ri/11
  - oracle: https://www.oracle.com/java/technologies/javase-jdk11-downloads.html
    • 有人能告诉我哪里做错了吗?我是不是应该对下载的Java SE开发工具包执行一些操作?我是不是应该将这些文件复制/粘贴到某个特定的位置?**

谢谢!
注:

> 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
}

> find.java()

$BrowserJavaVersion
[1] "11.341.2"

$CurrentVersion
[1] "1.8"

$`1.8`
$`1.8`$JavaHome
[1] "C:\\Program Files\\Java\\jre1.8.0_341"

$`1.8`$MicroVersion
[1] "0"

$`1.8`$RuntimeLib
[1] "C:\\Program Files\\Java\\jre1.8.0_341\\bin\\server\\jvm.dll"

$`1.8.0_341`
$`1.8.0_341`$JavaHome
[1] "C:\\Program Files\\Java\\jre1.8.0_341"

$`1.8.0_341`$MicroVersion
[1] "0"

$`1.8.0_341`$RuntimeLib
[1] "C:\\Program Files\\Java\\jre1.8.0_341\\bin\\server\\jvm.dll"

$`1.8.0_341`$MSI
[1] "<subkey>

> Sys.setenv(JAVA_HOME='C:\\Program Files\\Java\\jre1.8.0_341\\bin\\server\\jvm.dll')


> .libPaths()
[1] "C:/Users/me/OneDrive/Documents/R/win-library/4.1" "C:/Program Files/R/R-4.1.3/library" 

> sessionInfo()
R version 4.1.3 (2022-03-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 22000)

Matrix products: default

locale:
[1] LC_COLLATE=English_Canada.1252  LC_CTYPE=English_Canada.1252    LC_MONETARY=English_Canada.1252
[4] LC_NUMERIC=C                    LC_TIME=English_Canada.1252   

  > getwd()
[1] "C:/Users/me/OneDrive/Documents"

查询链接:

ecbunoof

ecbunoof1#

这是我的第一篇文章,所以我会尽我所能。在我的MacBook上安装Java SE Development Kit 11后,我在RStudio终端运行了以下代码:RCMD javareconf。它似乎已经纠正了JAVA_HOME以链接到正确的JAVA目录。然后我就可以运行r5r函数setup_r5()了。
我咨询了这个职位:https://community.rstudio.com/t/installing-rjava-in-mac-m1/137149
如果有用就告诉我。好的。

相关问题