Skip to content

Commit

Permalink
Merge pull request #297 from ncss-tech/quietCurl
Browse files Browse the repository at this point in the history
.soilDB_curl_get_JSON: suppress messages properly
  • Loading branch information
brownag authored Jun 13, 2023
2 parents a4467b9 + 69a4449 commit 03de2d7
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 10 deletions.
9 changes: 6 additions & 3 deletions R/AAAA.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,21 @@ 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()

dl <- try(curl::curl_download(
x,
tf,
quiet = TRUE,
quiet = quiet,
mode = ifelse(gzip, "wb", "w"),
handle = .soilDB_curl_handle()
), silent = TRUE)

if (inherits(dl, 'try-error')) {
message(dl[1])
if (!quiet) {
message(dl[1])
}
return(NULL)
}

Expand Down
6 changes: 3 additions & 3 deletions R/fetchKSSL.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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']]),
Expand Down
2 changes: 1 addition & 1 deletion R/fetchOSD.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
2 changes: 1 addition & 1 deletion R/seriesExtent.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
4 changes: 2 additions & 2 deletions R/siblings.R
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
Expand Down Expand Up @@ -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]]
Expand Down

0 comments on commit 03de2d7

Please sign in to comment.