26

I want to install rgdal for "R version 3.2.3 (2015-12-10)". I downloaded and installed

  • GDAL 1.11 Complete
  • PROJ framework v4.9.2-2
  • GEOS framework v3.5.0-1

from KyngChaos

Then in RStudio I typed install.packages("rgdal") which gave me this:

> .... 
> 
> configure: CC: clang configure: CXX: clang++ configure: rgdal:
> 1.1-1 checking for /usr/bin/svnversion... yes configure: svn revision: 
> 572 checking for gdal-config... 
> no no configure: error: gdal-config
> not found or not executable. ERROR: configuration failed for package
> ‘rgdal’
> * removing ‘/Library/Frameworks/R.framework/Versions/3.2/Resources/library/rgdal’
> Warning in install.packages :   installation of package ‘rgdal’ had
> non-zero exit status

> sessionInfo()
R version 3.2.3 (2015-12-10)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.10.5 (Yosemite)

locale:
[1] de_AT.UTF-8/de_AT.UTF-8/de_AT.UTF-8/C/de_AT.UTF-8/de_AT.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
[1] tools_3.2.3

I also tried in the terminal

R CMD INSTALL rgdal_1.1-1.tar --configure-args='--with-gdal-config=/Library/Frameworks/GDAL.framework/Programs/gdal-config
 --with-proj-include=/Library/Frameworks/PROJ.framework/Headers
 --with-proj-lib=/Library/Frameworks/PROJ.framework/unix/lib'

and

sudo R CMD INSTALL –configure-args=’–with-proj-include=/usr/local/lib’ rgdal_1.1-1.tar

No luck!

IRTFM
  • 258,963
  • 21
  • 364
  • 487
four-eyes
  • 10,740
  • 29
  • 111
  • 220
  • 1
    `devtools::session_info()` would be helpful to see the whole R+system config. I use Homebrew for the supporting library installs and have no trouble, but you may be able to add `export PATH=”/Library/Frameworks/GDAL.framework/Programs:$PATH”` (that's the path for `gdal-config` using the KC frameworks IIRC) to your profile and restart R/RStudio and try the install again. – hrbrmstr Dec 17 '15 at 11:48
  • @Phil added the info – four-eyes Dec 17 '15 at 11:54
  • If you type `gdal-config` in the terminal (not the R console) does it produce an error, or print something? – Phil Dec 17 '15 at 12:06
  • @hrbrmstr that did not do the trick – four-eyes Dec 17 '15 at 12:07
  • @Phil `bash: gdal-config: command not found` – four-eyes Dec 17 '15 at 12:07
  • It looks like there's a problem with your `GDAL` installation. I'd try downloading a fresh copy from KyngChaos of `GDAL Complete 1.11` and re-install it (just that, not the other libraries). – Phil Dec 17 '15 at 12:11
  • @Phil nope. that did not do the trick neither.... – four-eyes Dec 17 '15 at 12:20
  • what was successful for me was working with Xcode and macports; in terminal Window, I typed: sudo port install gdal; and then in RStudio, install.packages("rgdal", type='source') – MLavoie Dec 17 '15 at 12:30
  • @MLavoie I am not sure if I can use Macports because I work with `QGIS` which needs `GDAL` too... – four-eyes Dec 17 '15 at 12:31
  • There are also some instructions here to set up the appropriate path, and they seemed to get it working. May be worth a try: http://spatial.ly/2010/11/installing-rgdal-on-mac-os-x/ – Phil Dec 17 '15 at 12:32
  • @Phil thats what hbrmstr already suggested and I found that page too. Did not do the trick... – four-eyes Dec 17 '15 at 12:34
  • It's a long time since I installed this on a Mac but I don't remember it being this stubborn. Do you have `XCode` installed as @MLavoie suggests, that seems to ring a bell? – Phil Dec 17 '15 at 12:35
  • you can have both the framework and Homebrew versions installed. I have that on one OS X setup. I don't need QGIS everywhere. (a) are you _sure_ you got the right path to the `gdal-config` binary? (b) did you verify it's correct at a new terminal prompt? (c) did you try start R at the cmd line and doing the install vs use RStudio? – hrbrmstr Dec 17 '15 at 13:03
  • @Phil Yes. `XCode` is installed and up to date. – four-eyes Dec 17 '15 at 13:56
  • @hrbrmstr When I type `rgdal-config` at the bash I get something like `Usage: gdal-config [OPTIONS] Options:....`. However, no luck installing `rgdal`. Same error. What do you mean with your `(c)`? – four-eyes Dec 17 '15 at 14:03
  • RStudio is a different beast than R at the command-line. Often times the PATH does not get pushed through properly. – hrbrmstr Dec 17 '15 at 14:16
  • @hrbrmstr thanks. What you mentioned and what ive found online finally solved it. see my answere if your interested. – four-eyes Dec 17 '15 at 14:20

4 Answers4

29

Finally solved it.

Here is how I've done it! OS X 10.10.5 R 3.2.3 GDAL 1.1

  1. Download and install the GDAL Complete Framework from here
  2. Tell your OS X where to find the gdal-config file by typing this in you shell echo 'export PATH=/Library/Frameworks/GDAL.framework/Programs:$PATH' >> ~/.bash_profile and then source ~/.bash_profile
  3. Check if your GDAL is working fine by typing in the bash gdalinfo --version. That should come back with something like GDAL 1.11.3, released 2015/09/16.
  4. For most people, starting R and typing install.packages("rgdal") works (if you've done step 1-3). However, that was not the case for me. So, proceed with 5 if you're still having troubles.
  5. Go to the GDAL website and download the .tar file.
  6. In the shell, try this: sudo R CMD INSTALL –configure-args=’–with-proj-include=/usr/local/lib’ rgdal_1.1-1.tar. That still gave me an error: configure: error: proj_api.h not found in standard or given locations. ERROR: configuration failed for package ‘rgdal’
  7. So, you again need to tell where to find that one. Try:
R CMD INSTALL rgdal_1.1-1.tar --configure-args='--with-gdal-config=/Library/Frameworks/GDAL.framework/Programs/gdal-config
 --with-proj-include=/Library/Frameworks/PROJ.framework/Headers
 --with-proj-lib=/Library/Frameworks/PROJ.framework/unix/lib'

That should work. Try by starting R and type library(rgdal) in the R console.

Note: With rgoes I experienced similar problems. This helped me. Try:

R CMD INSTALL rgeos_0.3-15.tar --configure-args='--with-geos-config=/Library/Frameworks/GEOS.framework/unix/bin/geos-config
--with-proj-include=/Library/Frameworks/PROJ.framework/Headers
--with-proj-lib=/Library/Frameworks/PROJ.framework/unix/lib'

For pointing to the config file. It's here /Library/Frameworks/GEOS.framework/unix/bin/geos-config

wibeasley
  • 5,000
  • 3
  • 34
  • 62
four-eyes
  • 10,740
  • 29
  • 111
  • 220
  • @Phil Thanks, maybe someone will find it useful at one point :) – four-eyes Dec 17 '15 at 14:26
  • 2
    Thanks for this. Could not get it to work. Eventually got gdal installed using home brew in one line and the was able to install rgdal with no problem. This on OsX 10.11.3 R3.2.3 – user2498193 Feb 05 '16 at 16:44
  • Many thanks for this. Several useful tips. Needed to modify slightly to get the rgdal file name correct. Didn't manage to get rgeos R pkg installed with this. – IRTFM Apr 14 '16 at 23:11
  • Thanks, it works! However, I would like to know why this problem arises. – Irbin B. Aug 08 '18 at 04:53
  • @IrbinB. Well, it's because the software does not know where to look for certain files. Therefore, you have to manually tell it where to look for them. – four-eyes Aug 08 '18 at 06:43
  • @Stophface Thanks. I understand. But, the first time I install ESS in emacs, it worked like a charm, and I was able to install and use Rgdal, but as time passed, the troubles discussed in this question raised. So, I wanted to know the origin of this problem. Maybe this is not the best place to address it. – Irbin B. Aug 14 '18 at 23:38
  • @Stophface the link to the GDAL framework in your point #1 should be http://www.kyngchaos.com/software/frameworks (you have it with :frameworks instead of /frameworks) – Brent Brewington Jul 24 '19 at 22:31
  • Awesome. After trying the configure-args in step 7 (although using `install.packages()`) I got an error about not being able to find proj.db. I had to add the argument `--with-proj-share=/Library/Frameworks/PROJ.framework/unix/share/proj` as well. – Sam R May 21 '21 at 14:57
18

Quick note building on previous answer by @Stophface that might be useful to someone:

I did all steps listed above, but the rgdal installation in Terminal still gave me the error of configure: error: proj_api.h not found in standard or given locations. Yet (and without knowing exactly why), I managed to install it from R.app using pretty much the same specifications:

> install.packages('rgdal', type = "source", configure.args=c(
     '--with-gdal-config=/Library/Frameworks/GDAL.framework/Programs/gdal-config',
     '--with-proj-include=/Library/Frameworks/PROJ.framework/Headers',
     '--with-proj-lib=/Library/Frameworks/PROJ.framework/unix/lib'))

And thanks again for your answer!

Fran Villamil
  • 491
  • 4
  • 13
  • 1
    Bravo. Worked for me when the KingChaos solution did not. KingChaos had always succeeded before. – IRTFM Jan 14 '17 at 18:11
15

I had the same error Running R 3.4.0 on macOS Sierra (10.12). So I used homebrew to install gdal, then rgdal installed as per usual in R

in Terminal

brew update
brew install gdal

in R

install.packages("rgdal")

devtools::session_info()
Session info ----------------------------------------------------------------------------------------------------------------------------------------------
 setting  value                       
 version  R version 3.4.0 (2017-04-21)
 system   x86_64, darwin15.6.0        
 ui       RStudio (1.0.143)           
 language (EN)                        
 collate  en_AU.UTF-8                 
 tz       Australia/Melbourne         
 date     2017-04-24                  

Packages --------------------------------------------------------------------------------------------------------------------------------------------------
 package  * version date       source        
 devtools   1.12.0  2016-12-05 CRAN (R 3.4.0)
 digest     0.6.12  2017-01-27 CRAN (R 3.4.0)
 lattice    0.20-35 2017-03-25 CRAN (R 3.4.0)
 memoise    1.1.0   2017-04-21 CRAN (R 3.4.0)
 rgdal    * 1.2-6   2017-04-06 CRAN (R 3.4.0)
 sp       * 1.2-4   2016-12-22 CRAN (R 3.4.0)
 withr      1.0.2   2016-06-20 CRAN (R 3.4.0)
SymbolixAU
  • 25,502
  • 4
  • 67
  • 139
  • Thank you for this answer! I was manually downloading files not sure what was happening. I'm beyond thankful for the folks at [Homebrew](https://github.com/Homebrew/brew#homebrew). For anyone else who this might help, I had to run the following commands in Terminal: `$ brew update`, followed by `$ brew install gdal`. Then I installed [rgdal](https://cran.r-project.org/web/packages/rgdal/index.html) in R `install.packages( pkgs = "https://cran.r-project.org/src/contrib/rgdal_1.2-18.tar.gz", repos = NULL, type = "source")`. – Cristian E. Nuno Mar 17 '18 at 19:52
  • Really easy way. Thank you! – C. Guff Aug 05 '22 at 14:38
2

I installed it via conda on my Mac (OS X 10.10.5). The installation was simple. If you're new to conda, check this http://conda.pydata.org/docs/r-with-conda.html

conda install gdal
gdalinfo --version
# GDAL 2.1.0, released 2016/04/25

R Package installation:

install.packages('rgdal', type = "source", configure.args=c(
    '--with-gdal-config=/Library/Frameworks/GDAL.framework/Programs/gdal-config',
    '--with-proj-include=/Library/Frameworks/PROJ.framework/Headers',
    '--with-proj-lib=/Library/Frameworks/PROJ.framework/unix/lib'))

install.packages('rgeos', type = "source", configure.args=c(
    '--with-gdal-config=/Library/Frameworks/GDAL.framework/Programs/gdal-config',
    '--with-proj-include=/Library/Frameworks/PROJ.framework/Headers',
    '--with-proj-lib=/Library/Frameworks/PROJ.framework/unix/lib'))

install.packages('maptools', dependencies=TRUE)
Karthik Arumugham
  • 1,300
  • 1
  • 11
  • 18