Skip to content

Commit

Permalink
load module conditionally 🦆
Browse files Browse the repository at this point in the history
  • Loading branch information
cboettig committed Oct 25, 2023
1 parent ab63ac2 commit f4351d8
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions R/duckdb_config.R
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,17 @@ enable_parallel <- function(conn = cached_connection(),
#' @references <https://duckdb.org/docs/extensions/spatial.html>
#' @export
load_spatial <- function(conn = cached_connection()) {
status <- DBI::dbExecute(conn, "INSTALL 'spatial';")
status <- DBI::dbExecute(conn, "LOAD 'spatial';")

module <- "spatial"
ext <- duckdb_extensions(conn)
i <- which(ext$extension_name == module)

if(!ext$installed[[i]]) {
status <- DBI::dbExecute(conn, paste0("INSTALL '", module, "';"))
}
if(!ext$loaded[[i]]) {
status <- DBI::dbExecute(conn, paste0("LOAD '", module, "';"))
}
invisible(status)
}

Expand Down

0 comments on commit f4351d8

Please sign in to comment.