1

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?

sermomon
  • 254
  • 1
  • 11
  • 2
    There is almost certainly something between `also installing ...` and `Warning message` that provides more context. I'm going to _guess_, since [`units`](https://cran.r-project.org/web/packages/units/index.html) includes `SystemRequirements: udunits-2` that there is an underlying OS-level library not found (likely not installed). In [`r-quantities/units`](https://github.com/r-quantities/units), they suggest `sudo apt-get install libudunits2-dev` for debian/ubuntu (and they have other OS's commands), I suggest you try that approach to fix your problem. – r2evans Dec 29 '22 at 16:21
  • I get the same error when installing units using `install.packages("units")`. When I use `sudo apt-get install libudunits2-dev` it doesn't work either. – sermomon Dec 29 '22 at 16:58
  • 2
    I understand. You can get nowhere in this question, however, if you don't provide details for that claim. How does (in R) `install.packages("units")` fail? (Please include literal R console text.) How does (on a shell, not in R) `apt-get install libudunits2-dev` fail? (Please include literal shell console text.) – r2evans Dec 29 '22 at 17:00

3 Answers3

3

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!

Dirk Eddelbuettel
  • 360,940
  • 56
  • 644
  • 725
2

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. Depending on the underlying linux system you can do something like the below to install them.

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.packages(‘proxy’)
install.packages(‘e1071’)
install.packages(‘wk’)
install.packages(‘sp’)
install.packages(‘terra’)

Etcetera.

Robert Hijmans
  • 40,301
  • 4
  • 55
  • 63
  • Yes but you can a) pass a vector so `install.packages(c("proxy", "e1071", "wk", "sp", "terra"))` works and b) you have a repeated typo there ("pacakges"). But more importanly see my answer and how do it all *including all dependencies* via [r2u[(https://eddelbuettel.github.io/r2u/). – Dirk Eddelbuettel Dec 31 '22 at 15:16
  • 1
    Your answer is great. My point was that it can helpful to install dependencies one by one to see where the installation problem is. – Robert Hijmans Dec 31 '22 at 19:14
  • Gotcha. Incremental steps are indeed good for debugging. Having a system that avoids all this by taking of all "minutae" is even better and closer to what folks on other OSs get: I am really where [r2u](https://eddelbuettel.github.io/r2u/) got us, after various earlier attempts. – Dirk Eddelbuettel Dec 31 '22 at 20:04
2

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")
Andrew Chisholm
  • 6,362
  • 2
  • 22
  • 41