I'm trying to prepare a report to my colleagues and students. I think the best way to make it reproducible is through Google Colab. My analysis was performed using R and some packages available on CRAN.
I am using a Jupyter Notebook with R kernel. I used the followinf link to create a Notebook with netive R kernel: https://colab.research.google.com/notebook#create=true&language=r. As you can see as follows, its running R.
a <- 1
print(a)
However, when I try to install the exactextractr
package I get the following error:
install.packages("exactextractr")
Output:
Installing package into ‘/usr/local/lib/R/site-library’
(as ‘lib’ is unspecified)
also installing the dependencies ‘proxy’, ‘e1071’, ‘wk’, ‘sp’, ‘terra’, ‘classInt’, ‘s2’, ‘units’, ‘Rcpp’, ‘raster’, ‘sf’
Warning message in install.packages("exactextractr"):
“installation of package ‘units’ had non-zero exit status”
Warning message in install.packages("exactextractr"):
“installation of package ‘sf’ had non-zero exit status”
Warning message in install.packages("exactextractr"):
“installation of package ‘exactextractr’ had non-zero exit status”
The package was not installed:
library(exactextractr)
Output:
Error in library(exactextractr): there is no package called ‘exactextractr’
Traceback:
1. library(exactextractr)
What is the problem here?
CodePudding user response:
Some of the packages that you are trying to install (exactextractr, terra, sf, units) have system dependencies. You can see that on the CRAN pages for these packages (here for terra) under "SystemRequirements".
In this case, you need to have GDAL, GEOS, PROJ, and udunits-2
sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable
sudo apt-get update
sudo apt-get install libudunits2-dev libgdal-dev libgeos-dev libproj-dev
This is essentially what r2evans suggests in the comments. And there is no doubt in my mind that what he says is correct.
See the github pages for more guidance on installing these packages. Here for "terra".
Also, try to install the dependencies one by one, so that it becomes clearer where the problem is.
E.g.
install.pacakges(‘proxy’)
install.pacakges(‘e1071’)
install.pacakges(‘wk’)
install.pacakges(‘sp’)
install.pacakges(‘terra’)
Etcetera.
CodePudding user response:
Do this in one cell - R Colab doesn't support sudo directly.
system('sudo apt install libudunits2-dev')
Then this should work (I tried it successfully)
install.packages("exactextractr")
CodePudding user response:
Because the Linux variant underlying the GoogleColab is Ubuntu, you could also take advantage of r2u which brings about 20,000 binary CRAN packages with full dependencies to Ubuntu. So if (here) libudunits
is needed, it gets installed!
A have a quick demo gif in this tweet (as SO limits image sizes) -- 17s total for everything from a 'blank' start in a container with just R, and r2u set up. This works in any Ubuntu system on stanard x86_64 (ie Intel or AMD): laptop, desktop, server, cloud, continuous integration, ... Give it a try -- as the demo shows it installs correctly via a single install.packages("exactextractor")
from R!