R: How can I install terra on Amazon Linux 2? - r

I'm having some trouble running install.packages("terra") on Amazon Linux 2 with R 4.0.2 on an EC2. The output is the following:
checking GDAL: checking whether PROJ is available for linking:... yes
checking GDAL: checking whether PROJ is available fur running:... ./gdal_proj: error while loading shared libraries: libgdal.so.28: cannot open shared object file: No such file or directory
no
configure: error: OGRCoordinateTransformation() does not return a coord.trans: PROJ not available?
ERROR: configuration failed for package 'terra'
* removing '/usr/lib64/R/library/terra'
The downloaded source packages are in
'/tmp/RtmplRJO0R/downloaded_packages'
Updating HTML index of packages in '.Library'
Making 'packages.html' ... done
My understanding is that terra depends on compiled packages GDAL and PROJ. The best guide I found to install is this one. Unfortunately I still get the above error even though GDAL and PROJ are installed. Before this guide I tried using yum to install proj, but yum would install proj 4.8.0 which is too old to meet the minimum requirements for GDAL. Has anyone successfully installed terra on Amazon Linux 2?

Related

Cannot find cairo.h

Common problem, but there's no solution for me so far - so maybe you can help a lost bioinformatician with rather little experience in IT stuff.
I need to install Cairo in my R environment (R version 4.1.1) on my mac Big Sur 11.5.1 and get this error:
> install.packages("Cairo")
...
checking for pkg-config... /usr/local/bin/pkg-config
checking whether pkg-config knows about cairo... no
configure: CAIRO_LIBS is unset, attempting to guess it.
configure: CAIRO_CFLAGS=
checking if R was compiled with the RConn patch... no
checking cairo.h usability... no
checking cairo.h presence... no
checking for cairo.h... no
configure: error: Cannot find cairo.h! Please install cairo (http://www.cairographics.org/) and/or set CAIRO_CFLAGS/LIBS correspondingly.
ERROR: configuration failed for package ‘Cairo’
* removing ‘/Users/thomaslordick/opt/anaconda3/envs/seurat4/lib/R/library/Cairo’
The downloaded source packages are in
‘/private/var/folders/48/5h26d5297_92l76cvyjqvk2h0000gp/T/RtmpD4g5aI/downloaded_packages’
Updating HTML index of packages in '.Library'
Making 'packages.html' ... done
Warnmeldung:
In install.packages("Cairo") :
installation of package ‘Cairo’ had non-zero exit status
I already installed cairo-devel via sudo port install cairo, installed cairo via brew and also checked out similar threads (https://stat.ethz.ch/pipermail/r-help/2014-April/374096.html), where people recommend:
*Make sure you have cairo-devel installed, and remove the lines
export CAIRO_LIBS=${HOME}/usr/local/lib
export CAIRO_CFLAGS=${HOME}/usr/local/include
from your .bashrc file.*
I cant find a .bashrc file when using ls -la ~/... .
According to the above mentioned error I need to specify CAIRO_LIBS and CAIRO_CFLAGS. But where can I do this?
Thanks in advance,
Thomas
If using Conda for R environments, you are better off avoiding install.packages and instead make a point to always install through Conda. CRAN's Cairo package goes by r-cairo on Conda Forge. So,
conda install -n seurat4 -c conda-forge r-cairo

R package doesn't detect updated version of GDAL

I am trying to shift from raster to the new terra R package, which requires a recent version of GDAL to be installed on my machine (MacOS 10.14.6).
I updated GDAL following the instructions here: http://www.alexchubaty.com/post/2020-01-08-using-latest-gdal-macos-redux/ and it seemed to work. When I run gdalinfo --version in the terminal it displays:
GDAL 3.1.1, released 2020/06/22
But when I load the terra library in R it still seems to link to an old version of GDAL (2.4.2):
> library(terra)
This is terra version 0.7.11 (alpha-release)
NOTE: You are using GDAL version 2.4.2
For full functionality you need at least version 3.0.4
Interestingly, rgdal package seems to detect the updated version:
> library(rgdal)
Loading required package: sp
rgdal: version: 1.5-12, (SVN revision 1018)
Geospatial Data Abstraction Library extensions to R successfully loaded
Loaded GDAL runtime: GDAL 3.1.2, released 2020/07/07
Path to GDAL shared files: /usr/local/Cellar/gdal/3.1.2/share/gdal
GDAL binary built with GEOS: TRUE
Loaded PROJ runtime: Rel. 7.1.0, August 1st, 2020, [PJ_VERSION: 710]
Path to PROJ shared files: /Users/jamesmccarthy/Library/Application Support/proj:/usr/local/opt/proj/share/proj:/usr/local/Cellar/proj/7.1.0/share/proj
PROJ CDN enabled:FALSE
Linking to sp version:1.4-2
To mute warnings of possible GDAL/OSR exportToProj4() degradation,
use options("rgdal_show_exportToProj4_warnings"="none") before loading rgdal.
Attaching package: ‘rgdal’
The following object is masked from ‘package:terra’:
project
Does anyone know how to get terra to link to the most recent version of GDAL? I'm guessing the old version is still installed somewhere on the machine.
I am guessing that you installed rgdal from source, but the binary version of terra from CRAN. So after doing (what you already did) from the command line:
brew install pkg-config
brew install gdal
You should get what you are looking for with the following R command
install.packages("terra", type = "source")
Or, for the cutting edge
remotes::install_github("rspatial/terra")
Good luck with terra!

Install R 'sf' package on Centos -- gdal shared library error

How can I install the R 'sf' package on CentOS? On attempting to install, I initially got an error due to an out of date gdal package; I updated gdal (built from source following: http://trac.osgeo.org/gdal/wiki/BuildingOnUnix) and now have an error:
checking GDAL: linking with --libs only... yes
checking GDAL: /usr/local/share/gdal/pcs.csv readable... yes
checking GDAL: checking whether PROJ.4 is available for linking:... yes
checking GDAL: checking whether PROJ.4 is available fur running:...
./gdal_proj: error while loading shared libraries: libgdal.so.20: cannot open
shared object file: No such file or directory
no
configure: error: OGRCoordinateTransformation() does not return a
coord.trans:
PROJ.4 not available?
ERROR: configuration failed for package ‘sf’
I've tried creating a symlink to libgdal.so.20, but this doesn't change the error at all.
Add /usr/local/lib to e.g. /etc/ld.so.conf.d/libgdal-x86_64.conf
Run ldconfig
Restart R
Try again
#Dave has given exact steps & Please follow the below steps with some more explanation.
Add /usr/local/lib to e.g. /etc/ld.so.conf.d/libgdal-x86_64.conf Please create the file libgdal-x86_64.conf if doesn't exists.
#echo "/usr/local/lib" >> /etc/ld.so.conf.d/libgdal-x86_64.conf
Run ldconfig
#ldconfig
Make sure you have GEOS,GDAL,PROJ installed on your system.
#yum install proj.x86_64 proj-devel.x86_64 proj-epsg.x86_64 proj-nad.x86_64 geos*
Try again
Go to R cli & hit
install.packages("sf")
Thanks hope this helps
For anyone else who has a multi-user/multi-computer environment with the need to have multiple versions of various pieces of software installed, I fixed my issue with:
install.packages('sf',configure.args='--with-gdal-config=/sw/gdal/2.2.3-gcc4/bin/gdal-config --with-proj-include=/sw/proj/4.9.3-gcc4/include --with-proj-lib=/sw/proj/4.9.3-gcc4/lib --with-proj-share=/sw/proj/4.9.3-gcc4/share/proj')
Obviously you may/would have to alter path names from what I have.

How to install rgdal and rgeos package in R on university high performance computing system?

I have been installing R packages from tar.gz type files on Edinburgh university's compute and data facility which is a high performance computing cluster which is accessed via SSH. Once logged in, I can install the files as the example below:
install.packages("/exports/work/eng_AntonyHydroData/Pkges/DEoptim_2.2-3.tar.gz",rpeo=NULL,target="source")
There are approximately 40 packages and 38 of them install no problem, but two fail: RGEOS (rgeos_0.3-14.tar.gz) and RGDAL (rgdal_1.0-7.tar.gz).
The reason for failure is given below:
Installing package into '/exports/work/eng_AntonyHydroData/library'
(as 'lib' is unspecified)
inferring 'repos = NULL' from 'pkgs'
* installing *source* package 'rgdal' ...
** package 'rgdal' successfully unpacked and MD5 sums checked
configure: CC: gcc -std=gnu99
configure: CXX: g++
configure: rgdal: 1.0-5
checking for /usr/bin/svnversion... yes
configure: svn revision: 559
checking for gdal-config... no
no
configure: error: gdal-config not found or not executable.
ERROR: configuration failed for package 'rgdal'
Note that RGEOS gives the same reason i.e. gdal-config is missing.
I have looked around the net and have found various answers to this problem that mainly suggests to install libgeos-dev or something similar using the command 'sudo' or 'apt-get' but neither of these commands are recognised by the computing cluster system.
Any help in getting RGEOS and RGDAL to work would be very much appreciated.
Antony
I managed to solve this by first installing the geos-3.5.0.tar.bz2 package and issuing the following linux commands:
tar xjvf geos-3.5.0.tar.bz2
cd geos-3.5.0
./configure --help
mkdir /exports/work/....
./configure --help,
./configure --prefix=eng_A... --enable-python
make
make check
make install
and similar for rgdal
I'm not sure how your HPC system is setup but as the previous comment implied, you need "geos" installed/loaded. The system I work on uses the "module" command to load programs, so I use "module available" to find where "geos" is on the system so you can load it.
Here's an example from another system: http://docs.hpc.shef.ac.uk/en/latest/iceberg/software/apps/r.html

OSX - Can't configure rgdal for install

So I've been through a few problems trying to install rgdal. I'm running OS X 10.10.4
First I tried installing it from R :
install.packages("rgdal")
but the config file was not found :
configure: error: gdal-config not found or not executable.
So I installed gdal using Homebrew :
brew install gdal
Which installed a few dependencies alongside, like proj.
Problem is, R still can't install rgdal :
configure: error: proj_api.h not found in standard or given locations.
So I tried installing it manually, copying the rgdal_1.0-7.tar.gz from the temporary downloaded sources and unzipping it.
As ./config still seemed to fail finding proj_api.h, I searched it on my computer and found out it was in /usr/local/Cellar/proj/4.9.1/include, I tried
./configure CPPFLAGS="-I/usr/local/Cellar/proj/4.9.1/include"
... but it still doesn't work.
Now configure finds proj_api.h, but seems to be unable to find the functions defined in this header :
checking for proj_api.h... yes
checking for pj_init_plus in -lproj... no
configure: error: libproj not found in standard or given locations.
So now I don't know what to do anymore.
Any help would be great :)

Resources