R ubuntu xlsx package - r

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’

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")

(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.

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")

Related

rJava installation fails on macOS 10.14

After upgrading to MacOS Mojave (10.14.1), I'm no longer able to install rJava for R version 3.5.1 with Java version "1.8.0_102" installed.
I tried the previous solution for MacOS 10.11 but it still did not work, giving this error:
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 '/Library/Frameworks/R.framework/Versions/3.5/Resources/library/rJava/libs/rJava.so':
dlopen(/Library/Frameworks/R.framework/Versions/3.5/Resources/library/rJava/libs/rJava.so, 6): Library not loaded: /Library/Java/JavaVirtualMachines/jdk-9.jdk/Contents/Home/lib/server/libjvm.dylib
Referenced from: /Library/Frameworks/R.framework/Versions/3.5/Resources/library/rJava/libs/rJava.so
Reason: image not found
Posting the solution I found in case it helps others -- I don't quite understand why this work or if it's the right way so looking for better alternatives!
This issue lead to this Apple forum where it's stated
For legacy software that looks for the macOS headers in the base system under /usr/include, please install the package file located at: /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14. pkg
To do this, open terminal and run these commands
cd /Library/Developer/CommandLineTools/Packages/
open macOS_SDK_headers_for_macOS_10.14.pkg
then follow prompts to install the package.
After this, in the terminal, configure rJava and install as in the previous answer
sudo R CMD javareconf
R -e "install.packages('rJava')"
and it should install without problem.
After installing JDK 11.04 LTS I rain into the same error in R Studio on Mojave
R was expecting Library not loaded: /Library/Java/JavaVirtualMachines/jdk-11.0.1.jdk
Despite running sudo R CMD javareconf the error still persisted
Therefore I browsed to /Library/Java/JavaVirtualMachines/ in finder and renamed the folder "jdk-11.0.4.jdk" to "jdk-11.0.1.jdk"
Restarted R and both library(rJava) and library(xlsx) now work.
Hope this helps someone
I ran into the exact problem. I solved it by:
Install the latest version of Java (dmg file)
Install rJava in Studio: install.packages("rJava")
In the terminal: sudo mv jdk-12.0.1.jdk jdk-11.0.1.jdk
Otherwise the following error will appear in Rstudio:
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 '/Library/Frameworks/R.framework/Versions/3.5/Resources/library/rJava/libs/rJava.so':
dlopen(/Library/Frameworks/R.framework/Versions/3.5/Resources/library/rJava/libs/rJava.so, 6): Library not loaded: /Library/Java/JavaVirtualMachines/jdk-11.0.1.jdk/Contents/Home/lib/server/libjvm.dylib
Referenced from: /Library/Frameworks/R.framework/Versions/3.5/Resources/library/rJava/libs/rJava.so
Reason: image not found
In Rstudio: library(rJava)
rJava should have been loaded without issues.
I ran into same issue, when i was trying to install "rJava" in my macOs (Mojave version).
Below steps i executed to resolve issue.
R version : 3.6.1
issue : configure: error: one or more Java tools are missing.
*** JDK is incomplete! Please make sure you have a complete JDK. JRE is not sufficient.
solution : execute below command in your terminal
$ /usr/libexec/java_home -V
Matching Java Virtual Machines (1):
1.8.0_162, x86_64: "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk(your Java version)/Contents/Home
$ export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Home
$ export PATH=$JAVA_HOME/bin:$PATH
$ R CMD javareconf
$ R --quiet -e 'install.packages("rJava", type="source", repos="http://cran.us.r-project.org")'

Errors during installation of R dependencies after new R installation on Ubuntu 18.04

System: Ubuntu 18.04
Original error that showed up that prompted me to try to reinstall R and dependencies:
Error: package or namespace load failed for 'lubridate' in dyn.load(file, DLLpath = DLLpath, ...): unable to load shared object '/usr/local/lib/R/site-library/stringi/libs/stringi.so': libicui18n.so.57: cannot open shared object file: No such file or directory
Steps to reproduce:
Install R: apt install r-base
Try to install R dependencies: install.packages(c("dplyr", "lubridate", "qcc", "forecast"), repos='http://cran.us.r-project.org')
Error that displays during installation:
/usr/local/lib/R/site-library/BH/include/boost/smart_ptr/scoped_ptr.hpp:74:31: warning: 'template<class> class std::auto_ptr' is deprecated
Error that displays after installation:
The downloaded source packages are in
'/tmp/RtmpnulsEe/downloaded_packages'
Warning message:
In install.packages(c("dplyr", "lubridate", "qcc", "forecast", "stringi"), :
installation of package 'forecast' had non-zero exit status
After purging and reinstalling r-base and R dependencies, I'm seeing this...(already checked that libcurl4-openssl-dev was latest version):
Error: package or namespace load failed for 'forecast' in dyn.load(file, DLLpath = DLLpath, ...):
unable to load shared object '/usr/local/lib/R/site-library/curl/libs/curl.so':
/usr/lib/x86_64-linux-gnu/libcurl.so.4: version `CURL_OPENSSL_3' not found (required by /usr/local/lib/R/site-library/curl/libs/curl.so)
Update: Apparently it's something in the forecast library, because I reproduced that error like this:
$ R
> library(forecast)
Error: package or namespace load failed for 'forecast' in dyn.load(file, DLLpath = DLLpath, ...):
unable to load shared object '/usr/local/lib/R/site-library/curl/libs/curl.so':
/usr/lib/x86_64-linux-gnu/libcurl.so.4: version `CURL_OPENSSL_3' not found (required by /usr/local/lib/R/site-library/curl/libs/curl.so)
Your original problem is that stringi was built against a distro package version of libicu which changed. As this distribution package does not know you have lubridate in /usr/local it changes and breaks things.
There are a number of ways to fix this. The easiest (and narrowest) is to make sure you have libicu-dev installed. You could then reinstall (ie: rebuild stringi) after which lubridate will load.
For the rest you are just going somewhat wild throwing everything that is moveable up against the wall. You need to take a moment to realize that you can either install all these as binaries (ie from the Michael Rutter PPAs at launchpad), or from source. Your call. I have an older answer explaining the difference here (as well as in other follow-ups here) and we help on the r-sig-debian list too.
But in short: read this README at CRAN (esp first few paragraphs) and consider the PPAs.
After trying the following (purging and reinstalling R between each step):
apt purge r-base
Added/removed several different PPAs before realizing none of them supported Bionic Beaver. Result: Release not found.
Found Michael Rutter's PPA and attempted to use that. Result: same error message from above ('CURL_OPENSSL_3' not found).
Attempting several solutions to this SO article. Result: same error message from above ('CURL_OPENSSL_3' not found).
Read this article and performed the following in R:
> remove.packages("curl")
> install.packages("curl")
> install.packages(c("dplyr", "lubridate", "qcc", "forecast", "stringi", "curl"), repos='http://cran.us.r-project.org')
And everything worked as intended.

Installing ROracle (and the Oracle Instant Client?) on MacOS

I'm trying to install ROracle. Since ROracle requires the Oracle OCI libraries, I downloaded these files from the Oracle website: instantclient-basic-macos.x64-12.2.0.1.0, instantclient-sdk-macos.x64-12.2.0.1.0.zip. I put those files in ~/Library/Caches/Homebrew and install them using homebrew.
brew install instantclient-basic
brew install instantclient-sdk
The Oracle website also mentioned the need to set some environment variables, so I put this in my .bashrc file:
export LD_LIBRARY_PATH=/usr/local/Cellar/instantclient-basiclite/12.2.0.1.0/lib:$LD_LIBRARY_PATH
export DYLD_LIBRARY_PATH=/usr/local/Cellar/instantclient-basiclite/12.2.0.1.0/lib:$DYLD_LIBRARY_PATH
export NLS_LANG=UTF8
But trying to install ROracle in R leads to this:
> install.packages("ROracle")
Installing package into ‘/usr/local/lib/R/3.4/site-library’
(as ‘lib’ is unspecified)
trying URL 'https://cran.rstudio.com/src/contrib/ROracle_1.3-1.tar.gz'
Content type 'application/x-gzip' length 308252 bytes (301 KB)
==================================================
downloaded 301 KB
Warning in strptime(xx, f <- "%Y-%m-%d %H:%M:%OS", tz = tz) :
unknown timezone 'zone/tz/2017c.1.0/zoneinfo/America/Los_Angeles'
* installing *source* package ‘ROracle’ ...
** package ‘ROracle’ successfully unpacked and MD5 sums checked
configure: error: OCI libraries not found
ERROR: configuration failed for package ‘ROracle’
* removing ‘/usr/local/lib/R/3.4/site-library/ROracle’
Warning in install.packages :
installation of package ‘ROracle’ had non-zero exit status
R says it can't find the OCI libraries. Oracle's documentation has so far proven non-existent or worthless in resolving this issue, but I found a comment on the internet that seemed promising. So I wrote this into my .bashrc and ran it:
R CMD INSTALL --configure-args='--with-oci-lib=/usr/local/Cellar/instantclient-basic/12.2.0.1.0/lib --with-oci-inc=/usr/local/Cellar/instantclient-sdk/12.2.0.1.0/lib/sdk/include' ROracle_1.3-1.tar.gz
With this result:
installing to /usr/local/lib/R/3.4/site-library/ROracle/libs
** R
** inst
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
Error: package or namespace load failed for ‘ROracle’ in dyn.load(file, DLLpath = DLLpath, ...):
****unable to load shared object '/usr/local/lib/R/3.4/site-
library/ROracle/libs/ROracle.so':
dlopen(/usr/local/lib/R/3.4/site-library/ROracle/libs/ROracle.so, 6): Symbol
not found: _ons_recvthread_clone_sb
Referenced from: /usr/local/Cellar/instantclient-basic/12.2.0.1.0/lib/libons.dylib
Expected in: flat namespace
in /usr/local/Cellar/instantclient-basic/12.2.0.1.0/lib/libons.dylib
Error: loading failed
Execution halted
ERROR: loading failed
* removing ‘/usr/local/lib/R/3.4/site-library/ROracle’
So there's something wrong with libons.dylib? What am I supposed to do with that information?
The Instant Client 12.2 for macOS was patched. Get it from http://www.oracle.com/technetwork/topics/intel-macsoft-096467.html and unzip it, for example into ~/instantclient_12_2
I was able to install ROracle on macOS with:
brew install R
Update rpath in the library (using the correct version number for R):
install_name_tool -add_rpath ~/instantclient_12_2 /usr/local/Cellar/r/3.4.3/lib/R/bin/exec/R
Run 'R' and then:
install.packages("DBI")
Download ROracle_1.3-1.tar.gz from https://cran.r-project.org/web/packages/ROracle/index.html and install it:
R CMD INSTALL --configure-args='--with-oci-lib=/Users/cjones/instantclient_12_2 --with-oci-inc=/Users/cjones/instantclient_12_2/sdk/include' ROracle_1.3-1.tar.gz
A solution for that without -add_rpath can be found on Intall ROracle Package for Windows and Mac OS
I use R from Macports and I did:
cd /opt/local/Library/Frameworks/R.framework/Resources/lib
sudo ln -s ~/Applications/instantclient/libclntsh.dylib.12.1
sudo ln -s ~/Applications/instantclient/libclntshcore.dylib.12.1
sudo ln -s libclntsh.dylib.12.1 libclntsh.dylib
sudo ln -s libclntshcore.dylib.12.1 libclntshcore.dylib
I think only the link to libclntsh.dylib.12.1' is needed. But it does not harm to create the others as well. This way you do not need to runinstall_name_tool` after every upgrade to R.
After creating the links I was able to install ROracle using R CMD INSTALL

Jupyter notebook: error installing R packages

I'm using Ubuntu 16.04.
I have R running on my Jupyter notebook and all the packages comes with "R essentials" work fine.
However, when I try to install additional packages like "mice" or "bigmemory", the installation always fails. When it tries to do
** testing if installed package can be loaded
this is the error message that appears:
Error in dyn.load(file, DLLpath = DLLpath, ...) :
unable to load shared object '/home/usr/anaconda3/lib/R/library/bigmemory/libs/bigmemory.so':
/home/usr/anaconda3/lib/R/library/Rcpp/libs/../../../../libstdc++.so.6: version 'GLIBCXX_3.4.20' not found (required by /home/usr/anaconda3/lib/R/library/bigmemory/libs/bigmemory.so)
I have tried sudo apt-get install libstdc++6
and it says my libstdc++6 is installed and already is the newest version. I don't know why the R installer cannot find it..
I figured it out!
I got frustrated and uninstalled anaconda3 completely rm -rf ~\anaconda3. After reinstalling it, I looked at the instruction for installing IRkernel. I saw this:
If this fails, search the output for something like:
** testing if installed package can be loaded
Error in dyn.load(file, DLLpath = DLLpath, ...) :
unable to load shared object '/Users/[you]/anaconda/lib/R/library/rzmq/libs/rzmq.so':
dlopen(/Users/[you]/anaconda/lib/R/library/rzmq/libs/rzmq.so, 6): Library not loaded: libzmq.5.dylib
Referenced from: /Users/[you]/anaconda/lib/R/library/rzmq/libs/rzmq.so
Reason: image not found
This would mean that the R binary package of rzmq was compiled against a different version of libzmq from the one on your system.
It can be fixed by installing from source
So following the instruction I then did
install.packages('mice','/home/[usr]/anaconda3/lib/R/library/',type = 'source')
It worked! I did the same thing for 'bigmemory'. No error message and I can use them both on Jupyter notebook now.

Rgdal package installation on Amazon Linux AMI

I've installed geos, proj-4.8.0 and gdal-1.9.2, yet, after installing the R package rgeos, rgdal fails to install.
Here is a look at my home directory:
. . . and the error I get running install.packages("rgdal", type="source"):
** building package indices
** installing vignettes
** testing if installed package can be loaded
Error in dyn.load(file, DLLpath = DLLpath, ...) :
unable to load shared object '/mainstorage/michaeld/R/x86_64-redhat-linux-gnu-library/3.1/rgdal/libs/rgdal.so':
libgdal.so.1: cannot open shared object file: No such file or directory
Error: loading failed
Execution halted
ERROR: loading failed
* removing ‘/mainstorage/michaeld/R/x86_64-redhat-linux-gnu-library/3.1/rgdal’
The downloaded source packages are in
‘/tmp/Rtmpt51iFG/downloaded_packages’
Warning message:
In install.packages("rgdal", type = "source") :
installation of package ‘rgdal’ had non-zero exit status
I infer that this error has something to do with a dependent library. . . but that is all I gather.
I should mention that running sudo yum install libgdal1 libgdal1-dev libgeos libgeos-dev as suggested here yields the following:
No package libgdal1 available.
No package libgdal1-dev available.
Package geos-3.4.2-1.3.amzn1.x86_64 already installed and latest version
No package libgeos-dev available.
So, perhaps the better question is how do I install these dev packages?
Thanks for any direction.
You probably need to update the dynamic library cache, using ldconfig as superuser.
Alternatively, rather than building the packages from source, you can enable the Extra Packages for Enterprise Linux (EPEL) repository.

Resources