Skip to content

Instantly share code, notes, and snippets.

@dholstius
Last active April 13, 2018 19:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dholstius/59f2268d7fe62247b686 to your computer and use it in GitHub Desktop.
Save dholstius/59f2268d7fe62247b686 to your computer and use it in GitHub Desktop.
rgdal installation on OS X
install_from_source <- function (pkg, args = NULL, repos = "http://cran.rstudio.com", overwrite = FALSE, ...) {
if (!overwrite) {
if (pkg %in% installed.packages()) {
message(pkg, " is already installed")
return()
}
}
install.packages(
pkg,
configure.args = args,
repos = repos,
type = "source",
keep_outputs = TRUE,
verbose = TRUE)
}
usr_local_path <- function (...) file.path("/usr/local", ...)
homebrew_path <- function (...) usr_local_path("opt", ...)
stopifnot(dir.exists(homebrew_path()))
HOST_GUESS <- system("/usr/local/share/automake-1.15/config.guess", intern = TRUE)
message("HOST_GUESS is: ", HOST_GUESS)
########################################################################################
GDAL_CONFIG <- homebrew_path("gdal2", "bin", "gdal-config")
stopifnot(file.exists(GDAL_CONFIG))
PROJ_CONFIG_ARGS <- c(
paste0("--with-proj-include=", homebrew_path("proj", "include")),
paste0("--with-proj-share=", homebrew_path("proj", "share", "proj")),
paste0("--with-proj-lib=", homebrew_path("proj", "lib")))
RGDAL_CONFIG_ARGS <- c(
PROJ_CONFIG_ARGS,
#paste0("--host=", HOST_GUESS),
paste0("--with-gdal-config=", GDAL_CONFIG))
install_from_source("rgdal", args = RGDAL_CONFIG_ARGS, overwrite = TRUE)
########################################################################################
RGEOS_CONFIG_ARGS <- c(
paste0("--with-geos-config=", usr_local_path("bin", "geos-config")),
PROJ_CONFIG_ARGS)
install_from_source("rgeos", args = RGEOS_CONFIG_ARGS, overwrite = TRUE)
########################################################################################
SF_CONFIG_ARGS <- RGDAL_CONFIG_ARGS
install_from_source("sf", args = SF_CONFIG_ARGS, overwrite = TRUE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment