From d95574bf10396562b5495b18388a104092e0b0c3 Mon Sep 17 00:00:00 2001 From: Andrew Gene Brown Date: Sun, 6 Sep 2026 15:46:03 -0700 Subject: [PATCH 1/3] fix(createSSURGO): more consistent extraction of dbname across DBI connection types - use `DBI::dbGetInfo()` --- R/createSSURGO.R | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/R/createSSURGO.R b/R/createSSURGO.R index 7e7a0924..27052f41 100644 --- a/R/createSSURGO.R +++ b/R/createSSURGO.R @@ -276,13 +276,15 @@ createSSURGO <- function(filename = NULL, } } + # extract database name from DBIConnection (all types) + if (inherits(conn, 'DBIConnection')) { + filename <- DBI::dbGetInfo(conn)$dbname + } + # DuckDB has special spatial format, so it gets custom handling for IS_DUCKDB <- inherits(conn, "duckdb_connection") - if (inherits(conn, 'SQLiteConnection')) { - IS_GPKG <- grepl("\\.gpkg$", conn@dbname, ignore.case = TRUE)[1] - filename <- conn@dbname - } else { + if (!inherits(conn, 'SQLiteConnection')) { IS_GPKG <- grepl("\\.gpkg$", filename, ignore.case = TRUE)[1] if (is.na(IS_GPKG)) { IS_GPKG <- FALSE @@ -307,7 +309,7 @@ createSSURGO <- function(filename = NULL, ifelse(is.null(pattern), "*", pattern), "...") message( - " Output: ", ifelse(is.null(conn), filename, conn@dbname), "\n", + " Output: ", filename, "\n", " Spatial: ", paste0(include_spatial, collapse = ", "), "\n", " Tabular: ", paste0(include_tabular, collapse = ", ") ) From 7ad7dde72f0cdba08a50588d3802e2b8cb8b18cf Mon Sep 17 00:00:00 2001 From: Andrew Gene Brown Date: Sun, 6 Sep 2026 16:02:59 -0700 Subject: [PATCH 2/3] fix(createSSURGO): regex logic for customized spatial subset --- R/createSSURGO.R | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/R/createSSURGO.R b/R/createSSURGO.R index 27052f41..aa8aa69d 100644 --- a/R/createSSURGO.R +++ b/R/createSSURGO.R @@ -689,10 +689,12 @@ createSSURGO <- function(filename = NULL, idx <- paste0(shp.grp[, 1], "_", shp.grp[, 2]) %in% names(layer_names[layer_names %in% include_spatial]) shp.grp <- shp.grp[idx, , drop = FALSE] f.shp <- f.shp[idx] - f.shp.sc <- files[grepl(paste0( - paste0("soil", shp.grp[, 1], "_", shp.grp[, 2], "_", shp.grp[, 3]), - collapse = "|" - ), files)] + prefixes <- unique(paste0("soil", shp.grp[, 1], "_", shp.grp[, 2], "_")) + if (length(prefixes) > 0) { + f.shp.sc <- files[grepl(paste0("^(", paste(prefixes, collapse = "|"), ")"), basename(files))] + } else { + f.shp.sc <- character(0) + } include_spatial <- TRUE } From ea305005811a0ae2c4e4b034f2713b717b513294 Mon Sep 17 00:00:00 2001 From: Andrew Gene Brown Date: Sun, 6 Sep 2026 17:40:22 -0700 Subject: [PATCH 3/3] fix(createSSURGO): edge case in overwrite/append logic --- R/createSSURGO.R | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/R/createSSURGO.R b/R/createSSURGO.R index aa8aa69d..1bc1d4b6 100644 --- a/R/createSSURGO.R +++ b/R/createSSURGO.R @@ -561,9 +561,12 @@ createSSURGO <- function(filename = NULL, } else if (isTRUE(append)) { append_arg <- TRUE overwrite_arg <- FALSE - } else { + } else if (isTRUE(overwrite)) { append_arg <- FALSE - overwrite_arg <- overwrite + overwrite_arg <- TRUE + } else { + append_arg <- TRUE + overwrite_arg <- FALSE } rec <- .write_table_with_log(