diff --git a/DESCRIPTION b/DESCRIPTION index fd056932..74f59863 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: nhdplusTools Type: Package Title: NHDPlus Tools -Version: 1.2.0 +Version: 1.2.1 Authors@R: c(person(given = "David", family = "Blodgett", role = c("aut", "cre"), diff --git a/NEWS.md b/NEWS.md index d5174088..8eefade7 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,7 @@ +nhdplusTools 1.2.1 +========== +Bug fix for data cache directory #389 + nhdplusTools 1.2.0 ========== diff --git a/R/A_nhdplusTools.R b/R/A_nhdplusTools.R index ed648313..32802b15 100644 --- a/R/A_nhdplusTools.R +++ b/R/A_nhdplusTools.R @@ -305,7 +305,7 @@ nhdplusTools_data_dir <- function(dir = NULL) { nhdpt_dat_dir <- try(get("nhdpt_dat_dir", envir = nhdplusTools_env), silent = TRUE) - if(inherits(nhdpt_dat_dir, "try-error")) { + if(inherits(nhdpt_dat_dir, "try-error") || grepl("CRAN", nhdpt_dat_dir)) { assign("nhdpt_dat_dir", tools::R_user_dir("nhdplusTools"), envir = nhdplusTools_env) @@ -428,6 +428,18 @@ nhdplusTools_memoise_timeout <- function() { } } +.onLoad <- function(libname, pkgname) { + query_usgs_arcrest <<- memoise::memoise(query_usgs_arcrest, + ~memoise::timeout(nhdplusTools_memoise_timeout()), + cache = nhdplusTools_memoise_cache()) + query_usgs_geoserver <<- memoise::memoise(query_usgs_geoserver, + ~memoise::timeout(nhdplusTools_memoise_timeout()), + cache = nhdplusTools_memoise_cache()) + query_nldi <<- memoise::memoise(query_nldi, + ~memoise::timeout(nhdplusTools_memoise_timeout()), + cache = nhdplusTools_memoise_cache()) +} + #' @title Align NHD Dataset Names #' @description this function takes any NHDPlus dataset and aligns the attribute names with those used in nhdplusTools. #' @param x a \code{sf} object of nhdplus flowlines diff --git a/R/arcrest_tools.R b/R/arcrest_tools.R index 6386d871..77389cc7 100644 --- a/R/arcrest_tools.R +++ b/R/arcrest_tools.R @@ -45,7 +45,7 @@ get_3dhp_service_info <- memoise::memoise(function() { #' @importFrom httr RETRY content #' @importFrom dplyr filter #' @importFrom methods as -query_usgs_arcrest <- memoise::memoise(function(AOI = NULL, ids = NULL, +query_usgs_arcrest <- function(AOI = NULL, ids = NULL, type = NULL, where = NULL, t_srs = NULL, buffer = 0.5){ @@ -216,4 +216,4 @@ query_usgs_arcrest <- memoise::memoise(function(AOI = NULL, ids = NULL, all_out[[l]] <- out } tryCatch(sf::st_sf(data.table::rbindlist(all_out)), error = function(e) NULL) -}, ~memoise::timeout(nhdplusTools_memoise_timeout()), cache = nhdplusTools_memoise_cache()) +} diff --git a/R/geoserver_tools.R b/R/geoserver_tools.R index c70b1be5..b2fbf685 100644 --- a/R/geoserver_tools.R +++ b/R/geoserver_tools.R @@ -31,7 +31,7 @@ #' @importFrom methods as #' @importFrom xml2 read_xml -query_usgs_geoserver <- memoise::memoise(function(AOI = NULL, ids = NULL, +query_usgs_geoserver <- function(AOI = NULL, ids = NULL, type = NULL, filter = NULL, t_srs = NULL, buffer = 0.5) { @@ -177,7 +177,7 @@ query_usgs_geoserver <- memoise::memoise(function(AOI = NULL, ids = NULL, NULL } -}, ~memoise::timeout(nhdplusTools_memoise_timeout()), cache = nhdplusTools_memoise_cache()) +} unify_types <- function(out) { all_class <- bind_rows(lapply(out, function(x) { @@ -367,7 +367,7 @@ extact_comid_nwis <- memoise::memoise(function(nwis){ c <- rawToChar(httr::RETRY("GET", url)$content) f.comid <- jsonlite::fromJSON(c, simplifyVector = TRUE) f.comid$features$properties$comid -}, ~memoise::timeout(nhdplusTools_memoise_timeout()), cache = nhdplusTools_memoise_cache()) +}) #' @importFrom sf st_make_valid st_as_sfc st_bbox st_buffer st_transform check_query_params <- function(AOI, ids, type, where, source, t_srs, buffer) { diff --git a/R/get_geoconnex.R b/R/get_geoconnex.R index 7e8116ec..979049f7 100644 --- a/R/get_geoconnex.R +++ b/R/get_geoconnex.R @@ -7,7 +7,7 @@ #' @param url character url to get #' @return list containing parsed json on success, NULL otherwise #' @noRd -mem_get_json <- landing <- memoise::memoise(\(url) { +mem_get_json <- memoise::memoise(\(url) { tryCatch({ retn <- httr::RETRY("GET", url, httr::accept_json()) diff --git a/R/get_nldi.R b/R/get_nldi.R index 56323a38..325a7bc0 100644 --- a/R/get_nldi.R +++ b/R/get_nldi.R @@ -272,7 +272,7 @@ get_nldi_index <- function(location) { #' @importFrom httr GET #' @importFrom jsonlite fromJSON #' @noRd -query_nldi <- memoise::memoise(function(query, base_path = "/linked-data", parse_json = TRUE) { +query_nldi <- function(query, base_path = "/linked-data", parse_json = TRUE) { nldi_base_url <- paste0(get_nldi_url(), base_path) url <- paste(nldi_base_url, query, @@ -303,7 +303,7 @@ query_nldi <- memoise::memoise(function(query, base_path = "/linked-data", parse warning("Something went wrong accessing the NLDI.\n", e) NULL }) -}, ~memoise::timeout(nhdplusTools_memoise_timeout()), cache = nhdplusTools_memoise_cache()) +} #' @noRd check_nldi_feature <- function(nldi_feature, convert = TRUE) {