diff --git a/R/get_smips.R b/R/get_smips.R index 714fc12..6896540 100644 --- a/R/get_smips.R +++ b/R/get_smips.R @@ -13,7 +13,14 @@ #' Defaults to \dQuote{totalbucket}. #' @param day A single day's date to query, _e.g._, `day = "2017-12-31"`, both #' `Character` and `Date` classes are accepted. -#' +#' @param api_key A `character` string containing your \acronym{API} key, +#' a random string provided to you by \acronym{TERN}, for the request. +#' Defaults to automatically detecting your key from your local .Renviron, +#' .Rprofile or similar. Alternatively, you may directly provide your key as +#' a string here or use functionality like that from \CRANpkg{keyring}. If +#' nothing is provided, you will be prompted on how to set up your \R session +#' so that it is auto-detected and a browswer window will open at the +#' \acronym{TERN} website for you to request a key. #' @examples #' r <- get_smips(day = "2024-01-01") #' @@ -26,19 +33,20 @@ get_smips <- function(collection = "totalbucket", day, api_key = get_key()) { - day <- lubridate::ymd(day) url_date <- gsub("-", "", day) url_year <- lubridate::year(day) .check_collection_agreement(.collection = collection, .day = day) - approved_collections <- c("totalbucket", - "SMindex", - "bucket1", - "bucket2", - "deepD", - "runnoff") + approved_collections <- c( + "totalbucket", + "SMindex", + "bucket1", + "bucket2", + "deepD", + "runnoff" + ) collection <- rlang::arg_match(collection, approved_collections) collection_url <- data.table::fcase( @@ -56,14 +64,16 @@ get_smips <- function(collection = "totalbucket", paste0("smips_runoff_mm_", url_date, ".tif") ) - r <- terra::rast(paste0("/vsicurl/https://", - paste0('apikey:', api_key), - "@data.tern.org.au/model-derived/smips/v1_0/", - collection, - "/", - url_year, - "/", - collection_url)) + r <- terra::rast(paste0( + "/vsicurl/https://", + paste0("apikey:", api_key), + "@data.tern.org.au/model-derived/smips/v1_0/", + collection, + "/", + url_year, + "/", + collection_url + )) return(r) } @@ -73,8 +83,8 @@ get_smips <- function(collection = "totalbucket", .url_year <- lubridate::year(.day) if (.collection == "totalbucket" && - .url_year < 2005 || - .day > .last_week) { + .url_year < 2005 || + .day > .last_week) { cli::cli_abort("The data are not available before 2005 and past {.last_week}") } } diff --git a/man/get_smips.Rd b/man/get_smips.Rd index 581abeb..da0301f 100644 --- a/man/get_smips.Rd +++ b/man/get_smips.Rd @@ -21,6 +21,15 @@ Defaults to \dQuote{totalbucket}. \item{day}{A single day's date to query, \emph{e.g.}, \code{day = "2017-12-31"}, both \code{Character} and \code{Date} classes are accepted.} + +\item{api_key}{A \code{character} string containing your \acronym{API} key, +a random string provided to you by \acronym{TERN}, for the request. +Defaults to automatically detecting your key from your local .Renviron, +.Rprofile or similar. Alternatively, you may directly provide your key as +a string here or use functionality like that from \CRANpkg{keyring}. If +nothing is provided, you will be prompted on how to set up your \R session +so that it is auto-detected and a browswer window will open at the +\acronym{TERN} website for you to request a key.} } \value{ A \link[terra:rast]{terra::rast} object