Skip to content

Commit c880270

Browse files
committed
set GDAL_DATA path on win/macos binary installs
1 parent f7c26e1 commit c880270

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

R/init.R

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,18 +72,18 @@ sf_extSoftVersion = function() {
7272
names = c("GEOS", "GDAL", "proj.4", "GDAL_with_GEOS", "USE_PROJ_H", "PROJ"))
7373
}
7474

75-
if_exists_replace = function(var, new, where) {
76-
if (Sys.getenv(var) != "") {
75+
save_and_replace = function(var, value, where) {
76+
if (Sys.getenv(var) != "")
7777
assign(paste0(".sf.", var), Sys.getenv(var), envir = where)
78-
Sys.setenv(var = new)
79-
}
78+
# Sys.setenv(var = value) uses NSE and will set var, not the variable var points to:
79+
do.call(Sys.setenv, setNames(list(value), var))
8080
}
8181

8282
if_exists_restore = function(vars, where) {
8383
fn = function(var, where) {
8484
lname = paste0(".sf.", var)
8585
if (!is.null(get0(lname, envir = where)))
86-
Sys.setenv(var = get(lname, envir = where))
86+
do.call(Sys.setenv, setNames(list(get(lname, envir = where)), var)) # see above
8787
}
8888
lapply(vars, fn, where = where)
8989
}
@@ -93,14 +93,14 @@ load_gdal <- function() {
9393
if (file.exists(prj <- system.file("proj", package = "sf")[1])) {
9494
# nocov start
9595
if (! CPL_set_data_dir(prj)) { # if TRUE, uses C API to set path, leaving PROJ_LIB / PROJ_DATA alone
96-
if_exists_replace("PROJ_LIB", prj, .sf_cache)
97-
if_exists_replace("PROJ_DATA", prj, .sf_cache)
96+
save_and_replace("PROJ_LIB", prj, .sf_cache)
97+
save_and_replace("PROJ_DATA", prj, .sf_cache)
9898
}
9999
# CPL_use_proj4_init_rules(1L)
100100
# nocov end
101101
}
102102
if (file.exists(gdl <- system.file("gdal", package = "sf")[1]))
103-
if_exists_replace("GDAL_DATA", gdl, .sf_cache)
103+
save_and_replace("GDAL_DATA", gdl, .sf_cache)
104104
}
105105
CPL_gdal_init()
106106
register_all_s3_methods() # dynamically registers non-imported pkgs (tidyverse)

0 commit comments

Comments
 (0)