原本的 R 版本為 R version 3.5.4 不過因為系統更新的關系 就被更新到 R version 3.6.0 (2019-04-26) 

結果再要跑 library(xlsx) 的時候,就發現沒辦法載入 ,發現是rJava又出問題

環境是 Ubuntu 18.04 + R 3.6.0 + Rstudio 1.1.4.63

先講結論。似乎是重新安裝完 java 時 rstudio 要重新啟動,才不會一直跑一樣的錯。

sudo rstudio-server restart

Error: package or namespace load failed for ‘rJava’:
.onLoad failed in loadNamespace() for 'rJava', details:
  call: dyn.load(file, DLLpath = DLLpath, ...)
  error: unable to load shared object '/home/rstudio/R/x86_64-pc-linux-gnu-library/3.6/rJava/libs/rJava.so':
  libjvm.so: cannot open shared object file: No such file or directory
Error: loading failed
Execution halted
ERROR: loading failed
* removing ‘/home/rstudio/R/x86_64-pc-linux-gnu-library/3.6/rJava’

執行下面指令 安裝 UBUNTU 的JDK 
sudo apt-get install r-base-dev default-jdk

設定路徑
sudo R CMD javareconf

在R中安裝 ,或是使用RStudio裡,安裝。| 記得要將rstudio restart , 即使是主機重開機好像也不行
install.packages('rJava')

參考資料來源:

安裝rJava sdk
https://askubuntu.com/questions/1069463/not-able-to-install-rjava-in-r-ubuntu-18-04

重新啟動
https://support.rstudio.com/hc/en-us/community/posts/200646968-restarting-the-RStudio-Server-on-Ubuntu
https://support.rstudio.com/hc/en-us/articles/200532327-Managing-the-Server

> sessionInfo()
R version 3.6.0 (2019-04-26)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 18.10

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.8.0
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.8.0

Random number generation:
 RNG:     Mersenne-Twister 
 Normal:  Inversion 
 Sample:  Rounding 
 
locale:
 [1] LC_CTYPE=C.UTF-8          LC_NUMERIC=C              LC_TIME=C.UTF-8          
 [4] LC_COLLATE=C.UTF-8        LC_MONETARY=C.UTF-8       LC_MESSAGES=C.UTF-8      
 [7] LC_PAPER=C.UTF-8          LC_NAME=C.UTF-8           LC_ADDRESS=C.UTF-8       
[10] LC_TELEPHONE=C.UTF-8      LC_MEASUREMENT=C.UTF-8    LC_IDENTIFICATION=C.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] DT_0.7           ggplot2_3.2.0    shiny_1.3.2      stringr_1.4.0    curl_3.3        
 [6] rvest_0.3.4      xml2_1.2.0       anytime_0.3.3    dplyr_0.8.1      jsonlite_1.6    
[11] Rcrawler_0.1.9-1 httr_1.4.0       rJava_0.9-11     xlsx_0.6.1      

loaded via a namespace (and not attached):
 [1] tidyselect_0.2.5   webdriver_1.0.5    purrr_0.3.2        colorspace_1.4-1   htmltools_0.3.6   
 [6] yaml_2.2.0         base64enc_0.1-3    rlang_0.3.4        pillar_1.4.1       later_0.8.0       
[11] withr_2.1.2        glue_1.3.1         selectr_0.4-1      foreach_1.4.4      munsell_0.5.0     
[16] gtable_0.3.0       htmlwidgets_1.3    codetools_0.2-16   callr_3.2.0        crosstalk_1.0.0   
[21] doParallel_1.0.14  httpuv_1.5.1       ps_1.3.0           parallel_3.6.0     xlsxjars_0.6.1    
[26] Rcpp_1.0.1         xtable_1.8-4       promises_1.0.1     scales_1.0.0       debugme_1.1.0     
[31] mime_0.7           showimage_1.0.0    png_0.1-7          digest_0.6.19      stringi_1.4.3     
[36] processx_3.3.1     grid_3.6.0         tools_3.6.0        magrittr_1.5       lazyeval_0.2.2    
[41] tibble_2.1.3       crayon_1.3.4       RApiDatetime_0.0.4 pkgconfig_2.0.2    data.table_1.12.2 
[46] assertthat_0.2.1   rstudioapi_0.10    iterators_1.0.10   R6_2.4.0           compiler_3.6.0 

 

額外參考:

Installing the rJava package on Ubuntu is not quite as simple as most other R packages. Some quick notes on how to do it.

  1. Install the Java Runtime Environment (JRE).
    sudo apt-get install -y default-jre
  2. Install the Java Development Kit (JDK).
    sudo apt-get install -y default-jdk
  3. Update where R expects to find various Java files.
    sudo R CMD javareconf
  4. Install the package.
    > install.packages("rJava")
  5. If you have a RStudio session open, then exit and restart it. This is important (a running RStudio session will not pick up these changes!).

Sorted!

Hits: 13