I am installing packages such as 'rgdal', 'rsaga' and 'plotkml' on RStudio server. However, I get the following error message:
Warning messages:
1: In library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE, :
there is no package called ‘rgdal’
2: In library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE, :
there is no package called ‘RSAGA’
3: In library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE, :
there is no package called ‘plotKML’
But the same packages can be successfully installed and loaded on the Rstudio version of my laptop. Why am I having problems with the same packages on the server version of RStudio?
you need to install those beforehand. Could be the source of an issue if you haven't these. However, if no message at installation of rgdal, it should be fine...
Yes, install.packages("rgdal") was successful. But I cannot load it using library, I keep on getting this message: In library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE, :
there is no package called ‘rgdal’
That error message indicates that install.packages() was not successful, actually. It can be hard to see what’s going on with all the package installation messages when you’re not used to them!
Can you try running install.packages("rgdal", dependencies = TRUE) and paste the console output you see here?
Assuming RStudio Server is running on a different machine from your laptop, then there are two overlapping reasons the results can be different:
It’s a different machine, so it may be missing (or have outdated copies of) packages or non-R system requirements that the packages you are trying to install depend on
If your laptop is running Windows or Mac, then most of the packages you install may have pre-compiled binaries available, which reduces drastically the need for non-R system requirements. RStudio Server runs on Linux, where all packages must be built from source and therefore more system requirements come into the picture (e.g., as @cderv pointed out, rgdal needs GDAL >= 1.11.4 and PROJ.4 (proj >= 4.8.0) in order to compile from source).
If you don’t maintain the RStudio Server installation yourself, then you may have to talk to whoever does maintain it to get the right requirements and dependencies installed so that you can successfully install these packages.
install.packages("rgdal", dependencies = TRUE)
Installing package into ‘/home/gis/R/x86_64-redhat-linux-gnu-library/3.5’
(as ‘lib’ is unspecified)
trying URL 'https://cran.rstudio.com/src/contrib/rgdal_1.3-4.tar.gz'
Content type 'application/x-gzip' length 1664774 bytes (1.6 MB)
==================================================
downloaded 1.6 MB
installing source package ‘rgdal’ ...
** package ‘rgdal’ successfully unpacked and MD5 sums checked
configure: R_HOME: /usr/lib64/R
configure: CC: gcc -m64 -std=gnu99
configure: CXX: g++ -m64
configure: C++11 support available
configure: rgdal: 1.3-4
checking for /usr/bin/svnversion... yes
configure: svn revision: 766
checking for gdal-config... /usr/bin/gdal-config
checking gdal-config usability... yes
configure: GDAL: 1.11.4
checking GDAL version >= 1.11.4... yes
checking gdal: linking with --libs only... yes
checking GDAL: /usr/share/gdal/pcs.csv readable... yes
configure: pkg-config proj exists, will use it
configure: PROJ version: 4.8.0
checking proj_api.h presence and usability... no
configure: error: proj_api.h not found in standard or given locations.
ERROR: configuration failed for package ‘rgdal’
removing ‘/home/gis/R/x86_64-redhat-linux-gnu-library/3.5/rgdal’
Warning in install.packages :
installation of package ‘rgdal’ had non-zero exit status
The downloaded source packages are in
‘/tmp/RtmptZNuEp/downloaded_packages’
The Rstudio server is maintained externally. What are the procedures one needs to follow in order to get the right requirements and dependencies installed? Or perhaps, is there a script/code that installs all the dependencies at once?
So this is the rather cryptic line that tells you that package installation has failed (exit status = 0 means success). Looking up a few lines, the reason seems to be that there's a problem with the PROJ installation:
I haven't had to fix this before, myself, so I don't know if (re)installation of the library is necessary, or if it's just a matter of making sure there are pointers to it in the standard places R is looking. I hope somebody else with experience with this particular system requirement will chime in!
I'm not entirely sure what you mean, but it sounds like you will probably have to ask whoever administers the server to fix this for you. Most R packages do not have complex non-R system requirements, but for the ones that do (like rgdal), you usually need to look at the package's CRAN page under "System requirements" to see what the package requires, and then figure out how to install those non-R tools on your system. Sometimes this is as easy as using the Linux system's built-in package manager (e.g., apt or yum), but not always. Sometimes the R package maintainer will have a website with more detailed installation instructions (if so, it will also be linked from the CRAN page).
Briefly looking at the 3 packages you were having trouble with, here's what I see:
rgdal: we already established that it's not installing because of a problem with the PROJ installation on the server
plotKML: depends on rgdal (rgdal is in the "Imports" list), so it won't install until you've got rgdal installed successfully. It doesn't have any other external requirements, so if you can get rgdal installed, this one should install easily.
RSAGA: depends on rgdal, so it won't install until you've got rgdal installed successfully. Also has the system requirement of needing SAGA GIS (since it's just an R interface to the SAGA command line software). The Github page has a link for the SAGA GIS download.
Dealing with these sorts of external dependencies is definitely not much fun! If this is a popular combination of base system and spatial packages, it's possible that somebody else has made a script that will get everything set up at once — you could try web searching to see. Otherwise you (or whoever administers your server) probably needs to do it step by step.
P.S. It doesn't sound like this problem is actually specific to the RStudio IDE, so I changed the category to cut down on noise in the RStudio IDE channel (you can also do this yourself!).