30

I can't install the package "sf" on R. Seems there is an issue with gdal. No idea how to resolve it.

> install.packages("sf")

  There is a binary version available but the source version is later:
   binary source needs_compilation
sf  0.4-3  0.5-1              TRUE

Do you want to install from sources the package which needs compilation?
y/n: y
installing the source package ‘sf’

trying URL 'https://cran.rstudio.com/src/contrib/sf_0.5-1.tar.gz'
Content type 'application/x-gzip' length 4073881 bytes (3.9 MB)
==================================================
downloaded 3.9 MB

* installing *source* package ‘sf’ ...
** package ‘sf’ successfully unpacked and MD5 sums checked
configure: CC: clang
configure: CXX: clang++
checking for gdal-config... no
no
configure: error: gdal-config not found or not executable.
ERROR: configuration failed for package ‘sf’
* removing ‘/Library/Frameworks/R.framework/Versions/3.4/Resources/library/sf’
Warning in install.packages :
  installation of package ‘sf’ had non-zero exit status

The downloaded source packages are in
    ‘/private/var/folders/1m/w_zt5ygd26n_87h41qf574wc0000gn/T/RtmpNlYbwT/downloaded_packages’

Why does it say the download failed, then say the source packages are downloaded. What gives?

invictus
  • 1,821
  • 3
  • 25
  • 30
  • 1
    First off, it doesn't say the _download_ failed, but rather the installation. Also, GDAL is a C++ library used for geospatial vector manipulation, with a set of bindings for R. Looks like you need to install GDAL using your package manager of choice, then the R bindings for it, and then this `sf` package. – Sebastian Lenartowicz Jul 07 '17 at 14:52
  • Are you on Windows? I would try installing the binary first because I believe that will provide you with gdal. – jsta Jul 07 '17 at 14:53
  • No, on a Mac. Unable to install gdal via brew. Not sure how to troubleshoot. – invictus Jul 07 '17 at 15:13
  • 2
    As of Nov 2019, `brew install gdal` worked, and solved the problem. – peak Nov 04 '19 at 17:01

3 Answers3

21

Facing similar problem I have followed the steps below:

  1. On Terminal: gdalinfo --version to check which gdal version do you have. Mine was GDAL 2.2.0, released 2017/04/28 after brew update and brew upgrade
  2. From here: https://github.com/r-spatial/sf, instructions for macOS, as I have already gdal installed, I have used only brew unlink gdal and then brew link --force gdal2
  3. I reinstalled rgdal on R: install.packages("rgdal", repos = "http://cran.us.r-project.org", type = "source") and I have confirmed it was compiled with configure: GDAL: 2.2.0
  4. Finally, install.packages("sf") and it required to be compiled: binary source needs_compilation sf 0.5-3 TRUE
  5. Again, I have confirmed configure: GDAL: 2.2.0 and checking GDAL version >= 2.0.0... yes

After that, I have the new version installed: library(sf) Linking to GEOS 3.6.2, GDAL 2.2.0, proj.4 4.9.3

I hope it could be a solution for you too.

RgrNormand
  • 530
  • 4
  • 10
  • 2
    `rgdal::getGDALVersionInfo(str = "--version")` lets you determine which version of GDAL was used in rgdal. – Elin Jul 06 '18 at 11:40
2

The sf github page has installation instructions that include some information about this issue. In addition to following the steps there to install gdal with brew, I also had to install proj separately:

https://github.com/r-spatial/sf

mdg
  • 39
  • 8
0

Actually one simple resolution is downloading sf file from CRAN, then manually install it.

I have the same problem and solved using this method.

Mingze Li
  • 1
  • 3