Error loading rgdal - r

I have successfully installed the rgdal package along with the dependencies GDAL and Proj4. After installation I succesfully loaded the package in R with the library function. However after my most recent login when i type in the command library(rgdal) I get an error message:
Error: package or namespace load failed for 'rgdal' in dyn.load(file,
DLLpath = DLLpath, ...):
unable to load shared object '/home/nikhail1/R/x86_64-pc-linux-gnu-
library/3.4/rgdal/libs/rgdal.so':
libgdal.so.20: cannot open shared object file: No such file or directory
I understand this means there is no link to the libgdal file but I am not sure how to fix it. libgdal.so.20 is in the system under /home/nikhail1/bin/gdal/lib/. The rgdal.so file is under the rgdal folder in the R library in my /home/nikhail1/ system. I do not have the authority to perform an ldconfig function on shared libraries (I am a novice). Does anyone have a function that could help me make the system recognize the pathway to libgdal.so.20. I am working on a Linux CentOs 6.9 system. I cannot perform any sudo apt-get, yum or brew functions.
Many thanks, Nikhail

You can set LD_LIBRARY_PATH to include /home/nikhail1/bin/gdal/lib, i.e. in bash
export LD_LIBRARY_PATH="/home/nikhail1/bin/gdal/lib:$LD_LIBRARY_PATH"
ldd /home/nikhail1/R/x86_64-pc-linux-gnu-library/3.4/rgdal/libs/rgdal.so
should report libgdal.so.20 as been found. How to make this persistent depends on your desktop environment.

I've suffered quite a lot with gdal, rgdal and the proper setting of these in order to run rgdal functions in R. My bulletproof routine at the moment is the following:
UNINSTALL GDAL
sudo apt-get remove gdal-bin
Uninstall gdal-bin including dependent package
If you would like to remove gdal-bin and it's dependent packages which are no longer needed from Ubuntu,
sudo apt-get remove --auto-remove gdal-bin
Use Purging gdal-bin
If you use with purge options to gdal-bin package all the configuration and dependent packages will be removed.
sudo apt-get purge gdal-bin
If you use purge options along with auto remove, will be removed everything regarding the package, It's really useful when you want to reinstall again.
sudo apt-get purge --auto-remove gdal-bin
Just to be sure if you've tried and failed many times to install it and it doesn't work, run all of these in sequential order.
INSTALL GDAL
sudo apt-get update
sudo apt-get install gdal-bin proj-bin libgdal-dev libproj-dev -y
INSTALL RGDAL
IN R:
install.packages('rgeos', type='source')
install.packages('rgdal', type='source')
Now everything should load and run smooth.

Related

R ERROR: dependencies ‘xml2’, ‘httr’ are not available for package (Linux Mint 20.1)

I did not quite know where this belongs exactly, so I decided to post this here on stack overflow.
I recently had package issues with R and R-Studio on Linux Mint 20.1, where I always recieved dependency errors when installing packages like plotly and tidyverse. Therefore, in order to test if my system was responsible I live booted a fresh Linux Mint USB and installed R and R-Studio the following way:
sudo apt update
sudo apt dist-upgrade
sudo apt install r-base
Then download R-Studio from here and installed it like:
sudo apt-get install gdebi-core
# Install R-Studio with gdebi
sudo gdebi rstudio-1.2.5042-amd64.deb
Then, I opened RStudio by typing rstudio in the terminal. Inside RStudio I tried to install the package tidyverse by install.packages("tidyverse") which resulted in some dependency errors like:
ERROR: dependencies ‘xml2’, ‘httr’ are not available for package ‘rvest’
* removing ‘/home/mint/R/x86_64-pc-linux-gnu-library/3.6/rvest’
* installing *source* package ‘tibble’ ...
The solution was to use the command, suggested in the r-lib issue by #fredaas:
sudo apt install build-essential libcurl4-gnutls-dev libxml2-dev libssl-dev
By using this command I was able to resolve the issue and install every package I required flawlessly.
I am sorry if this does not belong here but I hope I can help someone saving hours of troubleshooting. This issues is maybe caused by Linux Mint or the most recent R Version 4.0.3 so I was not sure where to share my results.

Installing R `sf` and `RPostgres` packages on Unbuntu 18.04.4

Desire is to installed R {sf} and {RPostgres} packages on Ubuntu 18.04.4.
Trying:
R$> install.packages("sf")
configure: error: gdal-config not found or not executable.
Some SO searching (eg https://stackoverflow.com/a/49181048/2802810) suggests this:
sh$> sudo apt-get install libgdal-dev
The following packagess have unmet dependencies: libpq-dev :
Depends: libpq5 (= 10.12-0Ubuntu0.18.04.1) but 12.3-1.pgdg18.04+1 is
to be installed E: Unable to correct problems, you have broken
packages.
I also need libpq-dev for R {RPostgres}.
You may want to add PPA, depending on your R version.
https://launchpad.net/~marutter/+archive/ubuntu/c2d4u
https://launchpad.net/~marutter/+archive/ubuntu/c2d4u3.5
https://launchpad.net/~c2d4u.team/+archive/ubuntu/c2d4u4.0+
After adding PPA, you can install using sudo apt install r-cran-sf and sudo apt install r-cran-rpostgres
OKaaaay. The box I'm working in didn't have a Postgres repo installed (https://www.postgresql.org/download/linux/ubuntu/). Never libpq libs and that was all it needed.

Installing rgl and rgdal packages in R 3.3.2 on Ubuntu 16.10

I'm using R 3.3.2 and Ubuntu 16.10. I'm unable to install rgl and rgdal packages.
When I use
install.packages("rgl")
gives the following error message:
configure: error: X11 not found but required, configure aborted.
ERROR: configuration failed for package ‘rgl’
When I use
install.packages("rgdal")
gives the following error message:
configure: error: gdal-config not found or not executable.
ERROR: configuration failed for package ‘rgdal’
Edited
When I use
sudo apt-get install r-cran-rgl
in Ubuntu Terminal, it says
r-cran-rgl is already the newest version (0.95.1441-2)
However, the latest version of rgl is 0.96.0.
When I use
sudo apt-get install libgdal-dev libgeos++-dev
it throws the following error:
The following packages have unmet dependencies:
libgdal-dev : Depends: libopenjp2-7-dev but it is not going to be installed
I found a solution that was useful for me here: http://robinlovelace.net/r/2013/11/26/installing-rgdal-on-ubuntu.html.
In short, the solution would be this tree command lines:
sudo apt-get install aptitude # install aptitude as an alternative to apt-get
sudo aptitude install libgdal-dev # install the package (you may have to respond to queries here)
sudo aptitude install libproj-dev # install the proj.4 projection library
For rgl, just do sudo apt-get install r-cran-rgl.
For rgdal, follow the recommendation of the spatial folks eg here for sf and do this
add ubuntugis-unstable to the package repositories (e.g. with sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable and then sudo apt-get install libgdal-dev libgeos++-dev)
For general 'R on Ubuntu or Debian' questions, go to the r-sig-debian list.
Edit: Note that you don't need need ubuntugis-unstable repo if the current/older libgdal, libproj4 versions are good enough for you. Those are in the Ubuntu distro so just do sudo apt-get install ....
These installations worked for me provided that, in addition, I installed libxerces-c28. The need for the related shared object was indicated in the error log the first time I tried, after doing the installations indicated (libgdal, libgdal-dev, etc)

How can I install a R package on a offline Debian machine?

I have an Debian VM which is not connected to internet. Yet, I can still scp any file from my local machine which does have internet connection. To provide a little bit context, I am trying to host an shiny app on the VM.
I can still install an old version of R 3.1.1 with the "apt-get" command:
sudo apt-get update
sudo apt-get install r-base
sudo apt-get install r-base-dev
Yet, still can't find the "shiny" package when check the list:
sudo apt-cache search "^r-.*" | sort
So, I am thinking whether I could just scp the "shiny.tar.gz" to the VM and install the package locally? How could I install any R package offline?
I have tried somethings like:
install.packages('/home/mli/R/dir_pkg/shiny/shiny_0.13.2.tar.gz', repos = NULL, type = "source")
Yet, it didn't go through and error message as below:
Installing package into ‘/usr/local/lib/R/site-library’
(as ‘lib’ is unspecified)
Error in type == "both" :
comparison (1) is possible only for atomic and list types
Calls: install.packages
Execution halted
Then, I tried it with another "R CMD":
R CMD INSTALL /home/mli/R/dir_pkg/shiny/shiny_0.13.2.tar.gz
I got error message telling me that dependencies is missing:
* installing to library ‘/home/mli/R/x86_64-pc-linux-gnu-library/3.1’
ERROR: dependencies ‘httpuv’, ‘mime’, ‘jsonlite’, ‘xtable’, ‘digest’, ‘htmltools’, ‘R6’ are not available for package ‘shiny’
* removing ‘/home/mli/R/x86_64-pc-linux-gnu-library/3.1/shiny’
How can I successfully install shiny package from source? Should I go ahead to install all dependencies and dependencies of dependencies first?
Shiny has a few package dependencies, and "R CMD INSTALL" won't find them for you, so you need to get them manually. According to the description of shiny, it's dependencies are:
'Rcpp’, ‘httpuv’, ‘mime’, ‘jsonlite’, ‘xtable’, ‘digest’, ‘htmltools’, ‘R6’.
So first, get the packages from cran (below are current versions, but they do change over time. Note below is for the computer connected to the internet, you'll need to scp these to the offline computer before continuing):
wget https://cran.r-project.org/src/contrib/Rcpp_0.12.4.tar.gz
wget https://cran.r-project.org/src/contrib/httpuv_1.3.3.tar.gz
wget https://cran.r-project.org/src/contrib/mime_0.4.tar.gz
wget https://cran.r-project.org/src/contrib/jsonlite_0.9.19.tar.gz
wget https://cran.r-project.org/src/contrib/digest_0.6.9.tar.gz
wget https://cran.r-project.org/src/contrib/htmltools_0.3.5.tar.gz
wget https://cran.r-project.org/src/contrib/R6_2.1.2.tar.gz
wget https://cran.r-project.org/src/contrib/shiny_0.13.2.tar.gz
Then go through them in that same order with R CMD INSTALL. eg:
R CMD INSTALL Rcpp_0.12.4.tar.gz
Once all the dependencies are there, R CMD INSTALL should let you install shiny.
To install some package-offline on Debian you can use apt-offline :
apt-offline can fully update and upgrade an APT based distribution without connecting to the network, all of it transparent to APT.
apt-offline can be used to generate a signature on a machine (with no network). This signature contains all download information required for the APT database system. This signature file can be used on another machine connected to the internet (which need not be a Debian box and can even be running windows) to download the updates. The downloaded data will contain all updates in a format understood by APT and this data can be used by apt-offline to update the non-networked machine.
Install apt-offline on the offline os (Debian) then type the following command (to import missing keys) :
sudo apt-key exportall | sudo gpg --no-default-keyring --import --keyring /etc/apt/trusted.gpg
Then you need to get the signature of your_package_name:
apt-offline set debian-install.sig --install-packages your_package_name
Next step ,Upload debian-install.sig to the on-line system and download required files.
apt-offline get debian-install.sig --bundle debian-install.zip
Upload debian-install.zip file to the off-line system, install it using apt-offline utility to update APT database.
sudo apt-offline install debian-install.zip
install the specified packages your_package_name :
sudo apt-get install your_package_name
You can download your package using windows machine tuto
You are in a pickle. The R package mechanism expects you to be connected to get dependencies. That said, you can get some help:
R> AP <- available.packages(contrib.url(options("repos")$repos[1]))
R> revs <- tools::package_dependencies("shiny", AP, recursive=TRUE)[[1]]
R> revs
[1] "methods" "utils" "httpuv" "mime"
[5] "jsonlite" "xtable" "digest" "htmltools"
[9] "R6" "Rcpp" "tools" "stats"
R>
You can now look into AP again and feed this into download.packages().
Also, several (all ?) of these are in a newer Debian distro so you could use apt-get in download-mode (maybe using apt-offline as suggested in the other question).
Lastly, we do offer a Docker container for shiny so if you use that on your VM you don't need anything else.
sudo apt-get update
sudo apt-get install r-cran-digest
I can`t belive that it was so easy. I spent a long time searching and got only bad answers. This commands just solve everything.
I used it on trisquel
after checking all the answers on stackoverflow, I am not able to find exactly how to to install r-base on Debian/linux system. So, I have tried myself and able to run by below steps:
Run below command on internet working Linux machine in a custom folder.
apt-get download r-base r-base-core r-recommended libmpfr6 libisl19 cpp cpp-8 cpp-4 gcc cpp-8 binutils-common libbinutils binutils-x86-64-linux-gn gfortran linux-libc-dev g++ g++-8 libstdc make dpkg-dev perl-base perl-modules-5.28 libperl5.28 ibgdbm-compat4 zip unzip libpaper-utils xdg-utils libblas3 libblas.so.3 libcairo2 libcurl4 libgfortran5 libglib2.0-0 libice6 libicu63 libjpeg62-turbo liblapack3 liblapack.so.3 libpango-1.0-0 libpangocairo-1.0-0 libpng16-16 libsm6 libtcl8.6 libtiff5 libtk8.6 libx11-6 libxext6 libxss1 libxt6 ucf libfontconfig1 libfreetype6 libpixman-1-0 libxcb-render0 libxcb-shm0 libxcb1 libxrender1 libgssapi-krb5-2 libk5crypto3 libkrb5-3 libldap-2.4-2 libnghttp2-14 libpsl5 librtmp1 libssh2-1 libbsd0 x11-common fontconfig libfribidi0 libthai0 libcairo2:amd64 libfontconfig1 libfreetype6 libpango-1.0-0:amd64 libpangoft2-1.0-0 fontconfig-config libkeyutils1 libkrb5support0 libkeyutils1 libkrb5support0 libkeyutils1 libkrb5support0 libsasl2-2 libldap-common fontconfig-config libharfbuzz0b libpaper1 libsasl2-modules-db libthai-data libdatrie1 libwebp6 libjbig0 libxft2 libx11-data libxau6 libxdmcp6 fonts-dejavu-core ttf-bitstream-vera fonts-liberation libgraphite2-3 lsb-base sensible-utils r-cran-boot r-cran-cluster r-cran-foreign r-cran-kernsmooth r-cran-lattice r-cran-mgcv r-cran-nlme r-cran-rpart r-cran-survival r-cran-mass r-cran-class r-cran-nnet r-cran-spatial r-cran-codetools r-cran-matrix
This will create debian files inside the folder.
`Execute tar -zcf folder.tar.gz folder`
Copy this folder.tar.gz in offline computer and execute below command after going inside the folder.
dpkg -i *
Now check R in your system by typing
R --version

how to install R packages "RNetCDF" and "ncdf" on Ubuntu?

I would like to use the R packages RNetCDF and ncdf in Ubuntu.
When I try install.packages('RNetCDF') or install.packages('ncdf'), I get similar errors:
...
ncdf.c:3:20: fatal error: netcdf.h: No such file or directory
compilation terminated.
make: *** [ncdf.o] Error 1
ERROR: compilation failed for package ‘ncdf’
...
Warning message:
In install.packages("ncdf") :
installation of package ‘ncdf’ had non-zero exit status
The packages libnetcdf6 and netcdf-bin from the Ubuntu repository are installed. Do I need to do something else?
You need to install the -dev of those packages to get the headers that are required to compile the package. In this case, you need libnetcdf-dev, udunits-bin and libudunits2-dev
In my case, libudunits2-dev package was needed.
sudo apt-get install libudunits2-dev
Since I installed NetCDF from source, I had to manually specify the locations of lib and include folders
install.packages("/home/user/Downloads/RNetCDF_1.6.1-2.tar.gz",
repos = NULL,
type="source",
dependencies=FALSE,
configure.args="--with-netcdf-include=/usr/local/netcdf-4.2.1-build/include --with-netcdf-lib=/usr/local/netcdf-4.2.1-build/lib")
Just to clarify, since your initial issue is in R, and the fix is applied outside of R. I initially was trying to do
install.packages("libnetcdf-dev"), which didn't work.
instead, from outside of R: sudo apt-get install libnetcdf-dev
That fixed it for me.
In Ubuntu 20.04 LTS one can install the ncdf4 package (which supersedes ncdf), including all dependencies, with the bash command sudo apt install r-cran-ncdf4. Similarly for RNetCDF you can use sudo apt install r-cran-rnetcdf.

Resources