How to install the terra and raster libraries in R on Linux to manipulate .nc files?

218 Views Asked by At

I am trying to open and manipulate a .nc file (netcdf) in R. I have managed to install the ncdf4,RNetCDF, and ggplot2 packages. My issue is that when I try to install other packages to help me work with my files I get error messages such as "non zero exit status" (which I know means it was not installed), or a message about a package not being available for my version of R (I have 4.1.2).

I have tried to install the 'dependencies' listed in error messages first(after reading advice on here)-- but they won't install. I have typed an update command in my Linux terminal (which is how I got ncdf4 and RNetCDF to install). I have been searching all around online to find an answer--from GitHub, and directions from David W Peirce (who made ncview for Linux) and on this website--with no luck so far. I am not exactly sure how to operate with the ncdf4 library, but from my research I think I also need the raster library, the terra library, along with a few other libraries for spatial analysis.

My main issue is getting the raster and terra libraries to install. I have already tried: install.packages("raster") and install.packages("raster", dependencies = TRUE) and install.packages("terra").

Part of my final error message reads:

ERROR: configuration failed for package ‘terra’

  • removing ‘/home/******a/R/x86_64-pc-linux-gnu-library/4.1/terra’ Warning in install.packages : installation of package ‘terra’ had non-zero exit status

-Repeated with a bunch of littler packages such as "units" and "sf" and other things like that(which as I said earlier, I tried to install separately without success). How do I get terra and raster to install?

1

There are 1 best solutions below

0
On

As @Barry mentions in the comment above, r2u can help you. It add to Ubuntu LTS system 20.04 and 22.04 the ability to query an apt repo with all of CRAN along with almost 400 BioConductor packages. Plus, by using bspm you can access this from R.

It works on standard Ubuntu laptop and servers, or in containers, or in GitHub Actions, or in the could -- it works whereever Ubuntu LTS run.

Here is a quick demo I just scree-recorded installing terra in one install.packages("terra") command -- resulting in all fifty-plus required packages being installed in seconds. Give it a try!

(I didn't show raster becasue it is officially retired. r2u still has the binary. So if you do install.packages(c("terra", "raster")) you get both.)