R ubuntu xlsx package

3.2k Views Asked by At

I am trying to install xlsx package on Ubuntu in R in order to use a function allowing to insert links in R and then export them to Excel. Having said that, I simply can't install the package. Apparently it has to do wit rJava but I can't figure out a solution. Any hint? Here's the message I receive:

 Error : .onLoad failed in loadNamespace() for 'rJava', details:
 call: dyn.load(file, DLLpath = DLLpath, ...)
 error: unable to load shared object '/usr/lib/R/site-library/rJava    /libs/rJava.so':
 libjvm.so: cannot open shared object file: No such file or directory
 Error : package ‘rJava’ could not be loaded
 ERROR: lazy loading failed for package ‘xlsx’
* removing ‘/home/.../x86_64-pc-linux-gnu-library/3.2/xlsx’
 Warning in install.packages :
 installation of package ‘xlsx’ had non-zero exit status

 The downloaded source packages are in
  ‘/tmp/RtmpsjilCH/downloaded_packages’
3

There are 3 best solutions below

0
On

I'm reluctant to install Java on my own machine, but you could try installing a Java runtime environment:

sudo apt install default-jre

before trying again (perhaps starting by manually install rJava as @Bhas suggests).

Instead of a java-based solution though, why not try readxl which has no external dependencies:

install.packages("readxl")
0
On

In my experience you have to install java 11

sudo apt install default-jre
sudo apt install default-jdk

If java -version does not point to 11, use:

sudo ln -s /usr/lib/jvm/java-11-openjdk-amd64/bin/java /usr/bin/java

Then,

sudo R CMD javareconf

In R:

install.packages("rJava")
0
On

(I would post this in a comment but I do not have enough reputation)

I agree with @Phil 's advice, but I'd add a small note: readxl is from the tidyverse family and has no external dependencies, but it is not able to export data in .xls/.xlsx format. Nevertheless, readxl's own webpage suggests other dependency-free packages to export data into Excel format, like for example openxlsx. You might want to check that out.

Still, perhaps you could try to set dependencies = TRUE in the install.packages() command.