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

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.

Related

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

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?

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

Installing rgdal on MacOS with Anaconda RStudio

I have downloaded, compiled, and installed the necessary prerequisites (PROJ and GDAL). I ran the following command in RStudio:
install.packages("rgdal",lib="/Users/usr/anaconda3/lib/R/library", configure.args = "--with-proj-include=/Library/Frameworks/PROJ.framework/Versions/4B/unix/include --with-proj-lib=/Library/Frameworks/PROJ.framework/Versions/4B/unix/lib")
All of the checks and configurations work until...
checking proj_api.h presence and usability... no
configure: error: proj_api.h not found in standard or given locations.
This happens in spite of the fact that I specified the correct path for the include folder in the install.packages() call. I have also tried pointing to the Headers folder where the proj_api.h file is located, but that doesn't work either. Any insights into where I'm going wrong?

Problems with trying to to install rgdal package in R on Linux

I am trying to install the R (R version 3.2.4 Revised) package 'rgdal' onto my Linux, Ubuntu 14.04, but the package is having difficulties when it tries to load dependencies, specifically sqlite.
The error is as follows:
checking for gdal.h... yes
checking gdal: linking with --libs only... no
checking gdal: linking with --libs and --dep-libs... no
/usr/lib/libgdal.so: undefined reference to `sqlite3_column_table_name'
collect2: error: ld returned 1 exit status
I updated GDAL/OGR per the instructions here, because I thought that may be the issue. Now when I type gdalinfo or ogrinfo into the terminal a similar error appears:
gdalinfo: symbol lookup error: /usr/lib/libgdal.so.1: undefined
symbol: sqlite3_column_table_name
When I look in my usr/local/lib the following sqlite libraries are present:
libsqlite3.a libsqlite3.la libsqlite3.so libsqlite3.so.0
libsqlite3.so.0.8.6
The funny thing is that this package was working fine in R last week and now is broken...
Any help appreciated! Thanks.
-Caitlin
Stumbled across this error when I was trying to upgrade GDAL. The fix was to ENABLE_COLUMN_METADATA when I was configuring sqlite for install with
sudo CFLAGS="-DSQLITE_ENABLE_COLUMN_METADATA=1" ./configure
See the sqlite Compile-time options for more details
Sounds like a problem with that shared library, have install/update anything in your system without using your Package Manager? (I believe its apt?)
The libgdal.so.1 in your system was compiled against some version of the libsqlite libraries, which now after you updated something else, have changed but libgdal is still the same file.
I have never used Ubuntu, but in the Linux i use (arch) this is the reason partial updates are discouraged (like updating only one program, for example)
So I would recommend to try a full system update, or at least update the sqllite libraries.

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