From 3bb30d6df79824330e3c9dda1a9fe546083496c2 Mon Sep 17 00:00:00 2001 From: "Andrew G. Brown" Date: Tue, 13 Jun 2023 10:01:35 -0700 Subject: [PATCH 1/2] .soilDB_curl_get_JSON: suppress messages properly --- R/AAAA.R | 10 +++++++++- R/fetchKSSL.R | 6 +++--- R/fetchOSD.R | 2 +- R/seriesExtent.R | 2 +- R/siblings.R | 4 ++-- 5 files changed, 16 insertions(+), 8 deletions(-) diff --git a/R/AAAA.R b/R/AAAA.R index 39518b44..52648d9f 100644 --- a/R/AAAA.R +++ b/R/AAAA.R @@ -54,6 +54,12 @@ get_soilDB_env <- function() { #' @importFrom curl curl_download .soilDB_curl_get_JSON <- function(x, gzip = FALSE, FUN = jsonlite::fromJSON, ...) { tf <- tempfile() + + quiet <- list(...)[["quiet"]] + if (!is.logical(quiet) || is.na(quiet)) { + quiet <- FALSE + } + dl <- try(curl::curl_download( x, tf, @@ -63,7 +69,9 @@ get_soilDB_env <- function() { ), silent = TRUE) if (inherits(dl, 'try-error')) { - message(dl[1]) + if (!quiet) { + message(dl[1]) + } return(NULL) } diff --git a/R/fetchKSSL.R b/R/fetchKSSL.R index 0ea8f526..f8f8f13e 100644 --- a/R/fetchKSSL.R +++ b/R/fetchKSSL.R @@ -49,7 +49,7 @@ x <- URLencode(paste0('https://casoilresource.lawr.ucdavis.edu/soil_web/kssl/query.php?gzip=1&format=json&what=extended', f)) # list of dataframe objects; note: missing data are returned as FALSE - ext <- .soilDB_curl_get_JSON(x, gzip = TRUE) + ext <- .soilDB_curl_get_JSON(x, gzip = TRUE, quiet = TRUE) # done return(ext) @@ -62,7 +62,7 @@ x <- URLencode(paste0('https://casoilresource.lawr.ucdavis.edu/soil_web/kssl/query.php?gzip=1&format=json&what=nasis_morphologic', f)) # list of dataframe objects; note: missing data are returned as FALSE - m <- .soilDB_curl_get_JSON(x, gzip = TRUE) + m <- .soilDB_curl_get_JSON(x, gzip = TRUE, quiet = TRUE) # done return(m) @@ -76,7 +76,7 @@ x <- URLencode(paste0('https://casoilresource.lawr.ucdavis.edu/soil_web/kssl/query.php?gzip=1&format=json&what=site_hz', f)) # list of dataframe objects; note: missing data are returned as FALSE - site_hz <- .soilDB_curl_get_JSON(x, gzip = TRUE) + site_hz <- .soilDB_curl_get_JSON(x, gzip = TRUE, quiet = TRUE) # report missing data if (all(c(isFALSE(site_hz[['site']]), diff --git a/R/fetchOSD.R b/R/fetchOSD.R index 6e21a116..a34cbf0d 100644 --- a/R/fetchOSD.R +++ b/R/fetchOSD.R @@ -190,7 +190,7 @@ fetchOSD <- function(soils, colorState = 'moist', extended = FALSE) { } # attempt query to API, result is JSON - res <- .soilDB_curl_get_JSON(final.url, gzip = FALSE) + res <- .soilDB_curl_get_JSON(final.url, gzip = FALSE, quiet = TRUE) # errors are trapped above, returning NULL if (is.null(res)) { diff --git a/R/seriesExtent.R b/R/seriesExtent.R index 2c1f1b9d..0ef61e1f 100644 --- a/R/seriesExtent.R +++ b/R/seriesExtent.R @@ -75,7 +75,7 @@ seriesExtent <- function(s, type = c('vector', 'raster'), timeout = 60, # trapped errors return NULL if (is.null(res)) { - message('no data returned') + message('no data returned for series: ', s) return(NULL) } diff --git a/R/siblings.R b/R/siblings.R index 7087ee86..0ea17a08 100644 --- a/R/siblings.R +++ b/R/siblings.R @@ -53,7 +53,7 @@ siblings <- function(s, only.major = FALSE, component.data = FALSE, cousins = FA u <- URLencode(sprintf('https://casoilresource.lawr.ucdavis.edu/api/soil-series.php?q=siblings&s=%s', i)) # attempt query to API for basic sibling set, result is JSON - sib <- .soilDB_curl_get_JSON(u) + sib <- .soilDB_curl_get_JSON(u, quiet = TRUE) if (length(sib) >= 1) { sib <- sib[[1]] @@ -85,7 +85,7 @@ siblings <- function(s, only.major = FALSE, component.data = FALSE, cousins = FA # attempt query to API for component data, result is JSON # result is FALSE if no matching data - sib <- .soilDB_curl_get_JSON(u) + sib <- .soilDB_curl_get_JSON(u, quiet = TRUE) if (length(sib) >= 1) { sib <- sib[[1]] From 69a4449e8f60e7fe40576376d312a447cc12962f Mon Sep 17 00:00:00 2001 From: "Andrew G. Brown" Date: Tue, 13 Jun 2023 10:47:01 -0700 Subject: [PATCH 2/2] .soilDB_curl_get_JSON: fix for custom `FUN` actually, just add quiet as an argument, can't pass via ... --- R/AAAA.R | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/R/AAAA.R b/R/AAAA.R index 52648d9f..99a9d8df 100644 --- a/R/AAAA.R +++ b/R/AAAA.R @@ -52,18 +52,13 @@ get_soilDB_env <- function() { } #' @importFrom curl curl_download -.soilDB_curl_get_JSON <- function(x, gzip = FALSE, FUN = jsonlite::fromJSON, ...) { +.soilDB_curl_get_JSON <- function(x, gzip = FALSE, FUN = jsonlite::fromJSON, quiet = TRUE, ...) { tf <- tempfile() - quiet <- list(...)[["quiet"]] - if (!is.logical(quiet) || is.na(quiet)) { - quiet <- FALSE - } - dl <- try(curl::curl_download( x, tf, - quiet = TRUE, + quiet = quiet, mode = ifelse(gzip, "wb", "w"), handle = .soilDB_curl_handle() ), silent = TRUE)