Problems Installing rgeos and rgdal on Mac OS X High Sierra - r

I have looked at the multiple sources to figure out how to install rgeos and rgdal on Mac OS X High Sierra in a way that works with Anaconda Navigator. I mention Anaconda because I want to be able to build static project-specific, package environments to ensure that my projects work 6 months from now when the dependent packages change. I have successfully installed and used both rgeos and rgdal on a couple other computers but seem to be having issues on a new computer. I want to launch Shiny apps from Anaconda Navigator's RStudio. None of the solutions I found, listed below, worked:
https://dyerlab.ces.vcu.edu/2015/03/31/install-rgeos-on-osx/
https://cran.rstudio.com/web/packages/rgeos/rgeos.pdf
http://tlocoh.r-forge.r-project.org/mac_rgeos_rgdal.html
https://anaconda.org/conda-forge/r-rgdal
Based on the above sources and my slow progression through a series of error messages, I tried the following:
Install GDAL 2.2 Complete [30.0 MiB] 2018-3-10 from http://www.kyngchaos.com/software/frameworks. This installs GDAL, GEOS, PROJ, SQLite and UnixImageIO frameworks.
The above installed without an error message. But attempting to install rgeos gave an error message:
configure: error: geos-config not found or not executable.
Consequently, either the install failed and didn't notify me, or there is some type of $PATH issue (?). On a blog, someone suggested to do the following in response to the aforementioned issue:
brew install geos
The above completed successfully. So I went into RStudio and tried the following, which resolved the former error but produced a new one:
install.packages("~/Downloads/rgeos_0.3-28.tar.gz", repos = NULL, type = "source")
installing source package ‘rgeos’ ...
configure: CC: x86_64-apple-darwin13.4.0-clang
configure: CXX: x86_64-apple-darwin13.4.0-clang++
configure: rgeos: 0.3-28
checking for /usr/bin/svnversion... yes
cat: inst/SVN_VERSION: No such file or directory
configure: svn revision:
checking for geos-config... /usr/local/bin/geos-config
checking geos-config usability... yes
configure: GEOS version: 3.6.2
checking geos version at least 3.2.0... yes
checking geos-config clibs... yes
checking geos_c.h presence and usability... no
configure: error: geos_c.h not found in standard or given locations.
ERROR: configuration failed for package ‘rgeos’
removing ‘/Users/aloha2018/anaconda2/lib/R/library/rgeos’
Warning in install.packages :
installation of package ‘/Users/aloha2018/Downloads/rgeos_0.3-28.tar.gz’ had non-zero exit status
Any ideas on what to try next?
Naturally, I already tried in an RStudio application launched from Anaconda Navigator:
install.packages("rgeos")
install.packages("rgdal")
both from CRAN and from tar.gz. But it seems like it is unable to find a file called geos_c.h, which does indeed exist on my computer at:
/Library/Frameworks/GEOS.framework/Versions/3B/Headers/geos_c.h
Is there a way to tell RStudio to look in the directory containing that file so my rgeos and rgdal installations work? Are there other errors I should expect to encounter and if so, how do I avoid/resolve them?
I also tried in a Terminal window:
conda install -c conda-forge r-rgdal
but that fails after spending a long time attempting to "solve environment":
Andrews-MacBook-Pro:~ aloha2018$ conda install -c conda-forge r-rgdal
Solving environment: failed
UnsatisfiableError: The following specifications were found to be in conflict:
- r-rgdal
- rstudio==1.1.423
Use "conda info <package>" to see the dependencies for each package.
So I try:
conda r-rgdal
But there is no output:
Andrews-MacBook-Pro:~ aloha2018$ conda info r-rgdal
Andrews-MacBook-Pro:~ aloha2018$

I've had a similar issue. I first solved it by installing everything using conda using the following environment.yml configuration
name: london-crime-r
channels:
- conda-forge
- conda
dependencies:
- gdal
- geos
- r-base
- r-rcpp
- r-irkernel
- r-mass
- r-dplyr
- r-rgdal
- r-rgeos
- r-raster
- rstudio
However, after updating conda, resolving dependencies did not finish within the 10 hours so I went the traditional route:
Use brew to install geos and gdal. It takes 40 minutes to build on my machine.
brew install geos gdal
Once that has been achieved, install R packages in this sequence.
install.packages('sp', type='source')
install.packages("rgeos", repos="http://R-Forge.R-project.org", type="source")
require(rgeos)
install.packages("rgdal", repos="http://R-Forge.R-project.org", type="source")
require(rgdal)
Subsequently, the packages below are ok with the plain install.
libraries <- c("rgdal",
"rgeos",
"raster",
"spdep",
"spatstat")
install.packages(libraries)

Related

rgdal installed in Ubuntu 18.04 LTS, but R 3.5 not recognized it

I am trying to install 'rdgal' package in R 3.5 (Ubuntu 18.04), however, R shows this error:
configure: R_HOME: /opt/R/3.5.3/lib/R
configure: CC: gcc
configure: CXX: g++
configure: C++11 support available
configure: rgdal: 1.4-7
checking for /usr/bin/svnversion... yes
configure: svn revision: 845
checking for gdal-config... no
no
configure: error: gdal-config not found or not executable.
ERROR: configuration failed for package ‘rgdal’
* removing ‘/home/sergiob/R/x86_64-pc-linux-gnu-library/3.5/rgdal’
The downloaded source packages are in
‘/tmp/Rtmp0rrlnK/downloaded_packages’
Warning message:
In install.packages("rgdal") :
installation of package ‘rgdal’ had non-zero exit status
However, GDAL seems to be installed in the system, using gdalinfo --version
GDAL 2.2.3, released 2017/11/20
and using dpkg -l | grep gdal | cut -c-72 (seems that Ubuntu have two versions: 2.2 and 2.4)
ii gdal-bin 2.2.3+dfsg-2
ii gdal-data 2.4.2+dfsg-1~bionic0
ii libgdal20 2.2.3+dfsg-2
ii python-gdal 2.2.3+dfsg-2
ii python3-gdal 2.2.3+dfsg-2
Also, I have installed QGIS 3.13 (with a GDAL/ORG 2.2.3) but I cannot identify if this is the real problem.
I tried to re-install all dependencies and packages, including sudo apt-get install libgdal-dev libproj-dev, but not solve nothing.
I tried to review all posts about this issue, however, I can solve this problem yet.
Thre are a way to R to recognize the GDAL installed in Ubuntu 18.04?
The solution was to uninstall QGIS, and install GDAL first and re-install QGIS after.
Finally, the rGDAL was possible to be installed in R.

conda build R package fails due to C compiler

I'm trying to install an R package called rcdd using conda build and there is a problem with the C compiler. Note that this problem looks very similar to
Conda build R package fails at C compiler issue on MacOS Mojave however as (i) that question remains unanswered, and (ii) this relates to different package, I think this is not a duplicate question.
I'm using MacOS Mojave, conda 4.6.8. In a new conda environment with r-base and r-essentials
installed, I try
conda install conda-build
conda skeleton cran --recursive rcdd
conda build r-rcdd
and get the following error
* installing *source* package ‘rcdd’ ...
** package ‘rcdd’ successfully unpacked and MD5 sums checked
checking for gcc... x86_64-apple-darwin13.4.0-clang
checking whether the C compiler works... no
configure: error: in `/Users/pjethwa/miniconda3/envs/r_env/conda-bld/r-rcdd_1553173041138/work':
configure: error: C compiler cannot create executables
See `config.log' for more details
ERROR: configuration failed for package ‘rcdd’
The config.log file contains the same error message. This same error also appears when I try to install directly from R - i.e. using install.packages('rcdd'). I am able, however, to install this package using a version of R which was not installed by conda. This solution is unsatisfactory as I would like to use rpy2 to interface python and R, which seems to require that R be installed by conda (e.g. see Getting Segmentation fault Core dumped error while importing robjects from rpy2)
My clang/gcc versions are:
(r_env) myusername:~ clang --version
clang version 4.0.1 (tags/RELEASE_401/final)
Target: x86_64-apple-darwin18.2.0
Thread model: posix
InstalledDir: /Users/myusername/miniconda3/envs/r_env/bin
(r_env) myusername:~ gcc --version
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 10.0.0 (clang-1000.10.44.4)
Target: x86_64-apple-darwin18.2.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

Problem with R package installation: sf; system library not found

I am trying to install the R package sf. It mentions the system dependencies GDAL, GEOS and PROJ.4. I have installed all of these using
$sudo apt-get install libgdal-dev libgeos-dev libproj-dev proj-bin
However sf still complains that it is missing (something from?) the libraries:
$sudo R CMD INSTALL sf_0.6-3.tar.gz
[...]
configure: pkg-config proj exists, will use it
checking proj_api.h usability... yes
checking proj_api.h presence... yes
checking for proj_api.h... yes
configure: PROJ: 4.9.2
checking for pj_init_plus in -lproj... no
configure: error: libproj not found in standard or given locations.
ERROR: configuration failed for package ‘sf’
The same goes for using the install.packages("sf") command in R. I am using R version 3.5.0 on an Ubuntu 16.04 system, I managed to install the package on another computer with R version 3.4.3 but don't know what I did different to make it work then. Both apt and pkg-config --modversion proj say that the version is higher than needed (4.9.2) and i tried to find some info that could help me resolve the problem using pkg-config or on the internet but couldn't find anything. I did find the following line in /usr/include/proj_api.h (found using sudo apt-file search proj_api.h):
projPJ pj_init_plus(const char *);
which mentions the thing in the check not found, but I don't understand in what way it relates to this.
As a note, I do have two versions of R installed, I also have version 3.2.3 on the computer. Could this be a source of the problem? (I am sure, that the version I am installing the sf package to is 3.5)
EDIT
I have found another R package (proj4) with the libproj dependency and tried to install that one. While it did stop at the same error, this one gave a longer message:
>install.packages("proj4")
[...]
checking proj_api.h usability... yes
checking proj_api.h presence... yes
checking for proj_api.h... yes
checking for pj_init_plus in -lproj... no
configure: error: libproj and/or proj_api.h not found in standard search locations.
*** Install PROJ.4 and if necessary set PKG_CPPFLAGS/PKG_LIBS accordingly.
ERROR: configuration failed for package ‘proj4’
The PKG_CPPFLAGS/PKG_LIBS variables? are not found in R, and echo $PKG_LIBS showed nothing either. Might there be a way I could set these so that the packages can be installed?
I am thankful for any tips or hints as to what causes this.
Peter
I think you may be using older versions of libgdal-dev and you
the following question could be the issue you are seeing
Rgdal installation failed on ubuntu 16.04
sudo add-apt-repository -y ppa:ubuntugis/ubuntugis-unstable
sudo apt update
sudo apt install gdal-bin python-gdal python3-gdal libgdal1-dev

R Cairo package installation failed in Ubuntu 18.04

I attempt to install Cairo package in R under a Docker Ubuntu 18.04 container. Before installing the R Cairo package, I installed these packets in Ubuntu: libgtk2.0-dev, libcairo2-dev, xvfb, xauth, xfonts-base, r-base-dev, and libxt-dev.
However, when I installed Cairo package in R, I got the following error:
checking if R was compiled with the RConn patch... no
checking cairo.h usability... yes
checking cairo.h presence... yes
checking for cairo.h... yes
checking for PNG support in Cairo... yes
checking for ATS font support in Cairo... no
configure: CAIRO_LIBS=-lfreetype -lz -lpng16 -lz -lcairo -lXext -lXrender -lX11
checking for library containing deflate... no
checking whether Cairo programs can be compiled... configure: error: Cannot
compile a simple Cairo program. See config.log for details.
ERROR: configuration failed for package ‘Cairo’
* removing ‘/opt/conda/lib/R/library/Cairo’
The downloaded source packages are in
‘/tmp/RtmprETcPh/downloaded_packages’
Updating HTML index of packages in '.Library'
Making 'packages.html' ... done
Warning message:
In install.packages("Cairo") :
installation of package ‘Cairo’ had non-zero exit status
I've checked /tmp/RtmprETcPh/downloaded_packages, and there is only a filed called Cairo_1.5-9.tar.gz. And I don't know where to find config.log for more compile details of compiling a simple Cairo program.
Please help me to resolve out this issue if anybody know how to resolve out this issue.
Thank you
You may need to install the x11 dev libs since the docker container is likely not running these.
Try
sudo apt-get install libx11-dev
Under ubuntu 20.04, after installing libx11-dev, trying to install Cairo gave the error X11/Intrinsic.h not found. This is in libxt-dev. After installing this, Cairo could be installed.

rgdal package installation

The issue here is not exactly how to plot maps through R, as I have found already a pretty nice example here, but rather how to make it work. In fact, I am unable to load library rgdal:
library(rgdal)
Error in library(rgdal) : there is no package called ‘rgdal’
However, when I try to install the above package manually, I get the following error:
....
configure: error: proj_api.h not found in standard or given locations.
ERROR: configuration failed for package ‘rgdal’
* removing ‘/home/eualin/R/i686-pc-linux-gnu-library/2.15/rgdal’
Warning in install.packages : installation of package ‘/home/eualin/Downloads/rgdal_0.8-5.tar.gz’ had non-zero exit status
Any input welcome!
I f you look at the package page on CRAN, you will see the following :
SystemRequirements: for building from source: GDAL >= 1.7.1 library
from http://trac.osgeo.org/gdal/wiki/DownloadSource and PROJ.4 (proj >= 4.4.9) from http://trac.osgeo.org/proj/; GDAL OSX frameworks built by William Kyngesburye at http://www.kyngchaos.com/ may be used for
source installs on OSX.
As you seem to be under Linux, you always build package from source, so you will have to install the corresponding libraries on your system. If you are under Mint, Ubuntu or another Debian derivative, you can do :
$ sudo apt-get install libgdal1-dev libproj-dev
One tip that can be useful, still under a Debian based system, is to install the apt-file package and run :
$ sudo apt-file update
Then, when you get an error such as :
configure: error: proj_api.h not found in standard or given locations.
You can use the following command to find which package you must install to get the missing file :
$ apt-file search proj_api.h
libproj-dev: /usr/include/proj_api.h
If you use OS X with the Homebrew package manager, and have R installed through the homebrew-science tap, you can install rgdal by first installing gdal.
brew install gdal
You may first want to list the options available before you run this in case you want something fancy like postgresql support. To see the available options type
brew options gdal
then to be fancy you can type
brew install --with-postgresql gdal
after a while you should be good to go with dependencies, since proj including your needed proj_api.h are dependencies! Unfortunately, rgdal still won't find pro_api.h right now since it isn't looking in /usr/local/include. To fix this and other possible maladies with your rgdal installation, use the following R command to install rgdal:
> install.packages('rgdal', type = "source", configure.args=c('--with-proj-include=/usr/local/include','--with-proj-lib=/usr/local/lib'))
This should be similar to what you would also need for MacPorts with the exception of the brew steps, and your libraries/headers are most likely under "/opt/local/lib" and "/opt/local/include" respectively.
Note: to brew upgraders if you are using "--with-armadillo" as an option with gdal, and upgraded armadillo to 7 from 6. You will have to recompile gdal before you upgrade/reinstall rgdal.
On a Fedora 21 system using R-3.2.0, the following worked:
yum install gdal.x86_64 gdal-devel.x86_64 gdal-libs.x86_64
yum install proj.x86_64 proj-devel.x86_64
yum install proj-epsg.x86_64 proj-nad.x86_64
Obviously this was the result of repeated tries to get:
install.packages("rgdal")
to work. You can probably do it all in one install.
On ubuntustudio 14.04 (same for all debian distros):
sudo apt-get install libproj-dev libgdal-dev
Then I could install package rgdal
R info:
R version 3.0.2 (2013-09-25) -- "Frisbee Sailing"
Linux info:
Linux francois-K53SV 3.13.0-34-lowlatency #60-Ubuntu SMP PREEMPT Wed Aug 13 16:15:18 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
Here what i did on Centos7:
yum install gdal gdal-devel
yum install proj-devel
yum install proj-nad
yum install proj-epsg
Then simply
install.packages("rgdal")
Worked fine but it wasn't clear at all.
In OSX, I download proj from http://www.kyngchaos.com/software/frameworks and I run the following command in R.
install.packages('rgdal', type = "source", configure.args=c('--with-proj-include=/Library/Frameworks/PROJ.framework/Headers', '--with-proj-lib=/Library/Frameworks/PROJ.framework/unix/lib'))
For ubuntu 16.04 and R 3.5.1, this works quite fast:
sudo add-apt-repository -y ppa:ubuntugis/ubuntugis-unstable
sudo apt update
sudo apt install gdal-bin python-gdal python3-gdal libgdal1-dev
Then;
sudo apt-get install libudunits2-dev libgdal-dev libgeos-dev libproj-dev
Finally in CRAN;
install.packages("rgdal")
This worked for me:
install.packages('rgdal',repos="http://www.stats.ox.ac.uk/pub/RWin")
For Mac (OS.X Version10.12.6) users, This worked for me.
First, go to command line and install gdal using >> brew install gdal
Second, got to Rstuduio(R console) and install the package using install.packages("rgdal")
For me (Ubuntu 16.04, R 3.4.2), a mixture of the above solutions worked:
sudo apt-get install libudunits2-dev libgdal-dev libgeos-dev libproj-dev
Then simply installed rgdal from CRAN.
The only thing that worked on my system was to compile PROJ4 from source as described here and then instal the rgdal package as
install.packages("rgdal")
For people in multi-user environments with multiple versions of proj installed (from source), the method I used was:
install.packages('rgdal',configure.args="--with-proj-include=/sw/proj/4.9.2/include --with-proj-lib=/sw/proj/4.9.2/lib")
To fix this you need to install libgdal-dev:
$ sudo apt install libgdal-dev
If anyone still has issues on this, I got a version of rgdal from this site :
https://cran.r-project.org/web/packages/rgdal/index.html
and installed it :
install.packages("filename.tar", repos = NULL, type = "source")
None of the above answers worked for me (running R 3.5.1 on Linux Mint 17.1). GDAL version in the Ubuntu repositories is 1.11.3, this causes installation of rGDAL to fail. Here is the solution that worked for me (from this website):
sudo apt-get install libexpat1-dev
Download and install GDAL
wget http://download.osgeo.org/gdal/2.1.1/gdal-2.1.1.tar.gz
tar xvf gdal-2.1.1.tar.gz
cd gdal-2.1.1
./configure
sudo make
sudo make install
Verify version
gdal-config --version
I then got this error:
** testing if installed package can be loaded
Error in dyn.load(file, DLLpath = DLLpath, ...) :
unable to load shared object '/usr/local/lib/R/site-library/rgdal/libs/rgdal.so':
libgdal.so.20: cannot open shared object file: No such file or directory
Error: loading failed
Execution halted
ERROR: loading failed
This was fixed by updating the bindings:
sudo ldconfig
Then running install.packages("rgdal") in R worked fine.
Unable to get rgdal to install properly, I have tried all mentioned and all suggestions here R not finding package even after package installation
library(rgdal)
rgdal: version: 1.4-3, (SVN revision 828)
Geospatial Data Abstraction Library extensions to R successfully loaded
Loaded GDAL runtime: GDAL 2.2.3, released 2017/11/20
Path to GDAL shared files: C:/Users/xxx/Documents/R/win-library/3.4/rgdal/gdal
GDAL binary built with GEOS: TRUE
Loaded PROJ.4 runtime: Rel. 4.9.3, 15 August 2016, [PJ_VERSION: 493]
Path to PROJ.4 shared files: C:/Users/xxx/Documents/R/win-library/3.4/rgdal/proj
Linking to sp version: 1.3-1
Warning message:
package ‘rgdal’ was built under R version 3.4.4
I have upgraded my R to 3.6.1
Try again:
batch_gdal_translate(x, desc, outsuffix = "4.img", of = "HFA", co="TILED=YES")
NULL
Warning messages:
1: In gdal_setInstallation() :
No GDAL installation found. Please install 'gdal' before continuing:
- www.gdal.org (no HDF4 support!)
- www.trac.osgeo.org/osgeo4w/ (with HDF4 support RECOMMENDED)
- www.fwtools.maptools.org (with HDF4 support)
2: In gdal_setInstallation() : If you think GDAL is installed, please run:
gdal_setInstallation(ignore.full_scan=FALSE)
i have tried to run this from Rstudio & command line R 3.6.1 GUI.
all times I have tried this I get positive results for the libraries being installed.
library(raster)
Loading required package: sp
library(rgdal)
rgdal: version: 1.4-4, (SVN revision 833)
Geospatial Data Abstraction Library extensions to R successfully loaded
Loaded GDAL runtime: GDAL 2.2.3, released 2017/11/20
Path to GDAL shared files: C:/Users/xxx/Documents/R/R-3.6.1/library/rgdal/gdal
GDAL binary built with GEOS: TRUE
Loaded PROJ.4 runtime: Rel. 4.9.3, 15 August 2016, [PJ_VERSION: 493]
Path to PROJ.4 shared files: C:/Users/xxx/Documents/R/R-3.6.1/library/rgdal/proj
Linking to sp version: 1.3-1
library(gdalUtils)
Registered S3 method overwritten by 'R.oo':
method from
throw.default R.methodsS3
the files I am trying to read are dted files?
x <- list.files(path = src, pattern = ".dt", full.names = TRUE)
length(x)
batch_gdal_translate(x, desc, outsuffix = "4.img", of = "HFA", co="TILED=YES")
I have tried the above with GTIFF .tif format also and I get the same error.
But I am not trying to read .hdf files, just .dt0, .dt1, .dt2
this will work on another machine that I have R installed on, however, I am trying to figure out what is wrong with the installation I have on "this" machine.
Explicitly adding the include path in CFLAGS worked for me
install.packages('rgdal', type = "source", configure.args=c('CFLAGS=-I/apps/proj4/5.2.0/include'))
If you are using MacPorts this should work:
Install gdal (proj6 will be installed as a dependency)
sudo port install gdal
Install pkg-config
sudo port install pkgconfig
Set PKG_CONIFG_PATH variable to point to a directory with proj.pc file. In my case this was:
export PKG_CONFIG_PATH=/opt/local/lib/proj6/lib/pkgconfig
If you are using Conda environment please use:
conda install -c conda-forge r-rgdal
conda install -c conda-forge/label/broken r-rgdal
conda install -c conda-forge/label/cf201901 r-rgdal
conda install -c conda-forge/label/cf202003 r-rgdal
conda install -c conda-forge proj

Resources