From 27787aba702d20ba08ca63c23abee44b2b442f7b Mon Sep 17 00:00:00 2001 From: Martin Morgan Date: Sat, 14 Sep 2024 17:37:59 -0400 Subject: [PATCH] implement disk caching of API calls using memoise::memoise() - caching enabled by default, for 30 days - add `use_cache = FALSE` to most dataverse functions to temporarily disable use - set environment variable DATAVERSE_USE_CACHE to FALSE to disable across function calls --- DESCRIPTION | 3 +++ NAMESPACE | 4 ++++ R/onload.R | 29 +++++++++++++++++++++++++---- R/utils.R | 30 ++++++++++++++++++++++++------ man-roxygen/dots.R | 9 ++++++--- man/URLs.Rd | 8 +++++--- man/add_dataset_file.Rd | 8 +++++--- man/add_file.Rd | 8 +++++--- man/create_dataset.Rd | 8 +++++--- man/create_dataverse.Rd | 8 +++++--- man/dataset_atom.Rd | 8 +++++--- man/dataset_versions.Rd | 8 +++++--- man/dataverse_metadata.Rd | 8 +++++--- man/delete_dataset.Rd | 8 +++++--- man/delete_dataverse.Rd | 8 +++++--- man/delete_file.Rd | 8 +++++--- man/delete_sword_dataset.Rd | 8 +++++--- man/files.Rd | 8 +++++--- man/get_dataset.Rd | 8 +++++--- man/get_dataverse.Rd | 8 +++++--- man/get_facets.Rd | 8 +++++--- man/get_file_metadata.Rd | 8 +++++--- man/get_user_key.Rd | 8 +++++--- man/initiate_sword_dataset.Rd | 8 +++++--- man/list_datasets.Rd | 8 +++++--- man/publish_dataset.Rd | 8 +++++--- man/publish_dataverse.Rd | 8 +++++--- man/publish_sword_dataset.Rd | 8 +++++--- man/service_document.Rd | 8 +++++--- man/set_dataverse_metadata.Rd | 8 +++++--- tests/testthat.R | 7 +++++-- 31 files changed, 192 insertions(+), 90 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index b130c0e..5282a3c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -41,10 +41,13 @@ Authors@R: Imports: checkmate, httr, + memoise, + cachem, jsonlite, readr, stats, utils, + tools, xml2 Suggests: covr, diff --git a/NAMESPACE b/NAMESPACE index 32d841a..a24a77f 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -63,3 +63,7 @@ export(service_document) export(set_dataverse_metadata) export(update_dataset) export(update_dataset_file) +importFrom(cachem,cache_disk) +importFrom(checkmate,assert_character) +importFrom(checkmate,assert_logical) +importFrom(memoise,memoise) diff --git a/R/onload.R b/R/onload.R index 48de84a..e0fbc38 100644 --- a/R/onload.R +++ b/R/onload.R @@ -1,6 +1,27 @@ +#' @importFrom cachem cache_disk +#' +#' @importFrom memoise memoise .onLoad <- function(libname, pkgname) { - # a <- Sys.getenv("DATAVERSE_SERVER") - # if(a == "") { - # Sys.setenv("DATAVERSE_SERVER" = "dataverse.harvard.edu") - # } + # a <- Sys.getenv("DATAVERSE_SERVER") + # if(a == "") { + # Sys.setenv("DATAVERSE_SERVER" = "dataverse.harvard.edu") + # } + + ## implement API disk cache via 'memoise' + cache_directory <- file.path( + tools::R_user_dir(pkgname, "cache"), + "api_cache" + ) + get <- api_get_impl + if (!dir.exists(cache_directory)) { + status <- dir.create(cache_directory, recursive = TRUE) + if (!status) + warning("'dataverse' failed to create API cache") + } + if (dir.exists(cache_directory)) { + # disk cache with max age 30 days + cache <- cache_disk(cache_directory, max_age = 60 * 60 * 24 * 30) + get <- memoise(get, cache = cache) + } + api_get_memoized <<- get } diff --git a/R/utils.R b/R/utils.R index e411e60..dc62a13 100644 --- a/R/utils.R +++ b/R/utils.R @@ -206,14 +206,32 @@ api_url <- function(server = Sys.getenv("DATAVERSE_SERVER"), prefix = "api/") { } ## common httr::GET() uses -api_get <- function(url, ..., key = NULL, as = "text") { - if (!is.null(key)) - key <- httr::add_headers("X-Dataverse-key", key) - r <- httr::GET(url, ..., key) - httr::stop_for_status(r, task = httr::content(r)$message) - httr::content(r, as = as, encoding = "UTF-8") +#' @importFrom checkmate assert_character assert_logical +api_get <- function(url, ..., key = NULL, as = "text", use_cache = as.logical(Sys.getenv("DATAVERSE_USE_CACHE", TRUE))) { + assert_character(url, any.missing = FALSE, len = 1L, null.ok = TRUE) + assert_character(key, any.missing = FALSE, len = 1L, null.ok = TRUE) + assert_character(as, any.missing = FALSE, len = 1L, null.ok = TRUE) + assert_logical(use_cache, any.missing = FALSE, len = 1L) + if (use_cache) { + get <- api_get_memoized + } else { + get <- api_get_impl + } + get(url, ..., key = key, as = as) } +## cache implemented via memoization; memoized function defined in +## .onLoad() +api_get_impl <- function(url, ..., key = NULL, as = "text") { + if (!is.null(key)) + key <- httr::add_headers("X-Dataverse-key", key) + r <- httr::GET(url, ..., key) + httr::stop_for_status(r, task = httr::content(r)$message) + httr::content(r, as = as, encoding = "UTF-8") +} + +api_get_memoized <- NULL + # parse dataset response into list/dataframe parse_dataset <- function(out) { out <- jsonlite::fromJSON(out)$data diff --git a/man-roxygen/dots.R b/man-roxygen/dots.R index cf74d0d..38907cc 100644 --- a/man-roxygen/dots.R +++ b/man-roxygen/dots.R @@ -1,3 +1,6 @@ -#' @param ... Additional arguments passed to an HTTP request function, such as -#' \code{\link[httr]{GET}}, \code{\link[httr]{POST}}, or -#' \code{\link[httr]{DELETE}}. +#' @param ... Additional arguments passed to an HTTP request function, +#' such as \code{\link[httr]{GET}}, \code{\link[httr]{POST}}, or +#' \code{\link[httr]{DELETE}}. By default, HTTP requests use +#' values cached from previous identical calls. Use +#' \code{use_cache=FALSE} (or `Sys.setenv(DATAVERSE_USE_CACHE = +#' FALSE)` if cached API calls are not desired. diff --git a/man/URLs.Rd b/man/URLs.Rd index 822b272..d5429ba 100644 --- a/man/URLs.Rd +++ b/man/URLs.Rd @@ -85,9 +85,11 @@ available, download the original version instead of the ingested? If there was no ingested version, is set to NA. Note in \verb{get_dataframe_*}, \code{original} is set to FALSE by default. Either can be changed.} -\item{...}{Additional arguments passed to an HTTP request function, such as -\code{\link[httr]{GET}}, \code{\link[httr]{POST}}, or -\code{\link[httr]{DELETE}}.} +\item{...}{Additional arguments passed to an HTTP request function, +such as \code{\link[httr]{GET}}, \code{\link[httr]{POST}}, or +\code{\link[httr]{DELETE}}. By default, HTTP requests use +values cached from previous identical calls. Use +\code{use_cache=FALSE} (or \code{Sys.setenv(DATAVERSE_USE_CACHE = FALSE)} if cached API calls are not desired.} \item{filename}{Filename of the dataset, with file extension as shown in Dataverse (for example, if nlsw88.dta was the original but is displayed as the ingested diff --git a/man/add_dataset_file.Rd b/man/add_dataset_file.Rd index 4e6e7f2..adf3e1c 100644 --- a/man/add_dataset_file.Rd +++ b/man/add_dataset_file.Rd @@ -47,9 +47,11 @@ be set as a default via an environment variable. To set a default, run or add \verb{DATAVERSE_SERVER = "dataverse.harvard.edu} in one's \code{.Renviron} file (\code{usethis::edit_r_environ()}), with the appropriate domain as its value.} -\item{...}{Additional arguments passed to an HTTP request function, such as -\code{\link[httr]{GET}}, \code{\link[httr]{POST}}, or -\code{\link[httr]{DELETE}}.} +\item{...}{Additional arguments passed to an HTTP request function, +such as \code{\link[httr]{GET}}, \code{\link[httr]{POST}}, or +\code{\link[httr]{DELETE}}. By default, HTTP requests use +values cached from previous identical calls. Use +\code{use_cache=FALSE} (or \code{Sys.setenv(DATAVERSE_USE_CACHE = FALSE)} if cached API calls are not desired.} \item{id}{An integer specifying a file identifier; or, if \code{doi} is specified, a character string specifying a file name within the DOI-identified dataset; or an diff --git a/man/add_file.Rd b/man/add_file.Rd index 903b6a7..e6d08b5 100644 --- a/man/add_file.Rd +++ b/man/add_file.Rd @@ -30,9 +30,11 @@ be set as a default via an environment variable. To set a default, run or add \verb{DATAVERSE_SERVER = "dataverse.harvard.edu} in one's \code{.Renviron} file (\code{usethis::edit_r_environ()}), with the appropriate domain as its value.} -\item{...}{Additional arguments passed to an HTTP request function, such as -\code{\link[httr]{GET}}, \code{\link[httr]{POST}}, or -\code{\link[httr]{DELETE}}.} +\item{...}{Additional arguments passed to an HTTP request function, +such as \code{\link[httr]{GET}}, \code{\link[httr]{POST}}, or +\code{\link[httr]{DELETE}}. By default, HTTP requests use +values cached from previous identical calls. Use +\code{use_cache=FALSE} (or \code{Sys.setenv(DATAVERSE_USE_CACHE = FALSE)} if cached API calls are not desired.} } \value{ An object of class \dQuote{dataset_atom}. diff --git a/man/create_dataset.Rd b/man/create_dataset.Rd index 489c4aa..7989a97 100644 --- a/man/create_dataset.Rd +++ b/man/create_dataset.Rd @@ -39,9 +39,11 @@ be set as a default via an environment variable. To set a default, run or add \verb{DATAVERSE_SERVER = "dataverse.harvard.edu} in one's \code{.Renviron} file (\code{usethis::edit_r_environ()}), with the appropriate domain as its value.} -\item{...}{Additional arguments passed to an HTTP request function, such as -\code{\link[httr]{GET}}, \code{\link[httr]{POST}}, or -\code{\link[httr]{DELETE}}.} +\item{...}{Additional arguments passed to an HTTP request function, +such as \code{\link[httr]{GET}}, \code{\link[httr]{POST}}, or +\code{\link[httr]{DELETE}}. By default, HTTP requests use +values cached from previous identical calls. Use +\code{use_cache=FALSE} (or \code{Sys.setenv(DATAVERSE_USE_CACHE = FALSE)} if cached API calls are not desired.} \item{dataset}{A character specifying a persistent identification ID for a dataset, for example \code{"doi:10.70122/FK2/HXJVJU"}. Alternatively, an object of class diff --git a/man/create_dataverse.Rd b/man/create_dataverse.Rd index a215035..11c817c 100644 --- a/man/create_dataverse.Rd +++ b/man/create_dataverse.Rd @@ -27,9 +27,11 @@ be set as a default via an environment variable. To set a default, run or add \verb{DATAVERSE_SERVER = "dataverse.harvard.edu} in one's \code{.Renviron} file (\code{usethis::edit_r_environ()}), with the appropriate domain as its value.} -\item{...}{Additional arguments passed to an HTTP request function, such as -\code{\link[httr]{GET}}, \code{\link[httr]{POST}}, or -\code{\link[httr]{DELETE}}.} +\item{...}{Additional arguments passed to an HTTP request function, +such as \code{\link[httr]{GET}}, \code{\link[httr]{POST}}, or +\code{\link[httr]{DELETE}}. By default, HTTP requests use +values cached from previous identical calls. Use +\code{use_cache=FALSE} (or \code{Sys.setenv(DATAVERSE_USE_CACHE = FALSE)} if cached API calls are not desired.} } \value{ A list. diff --git a/man/dataset_atom.Rd b/man/dataset_atom.Rd index 22631e8..4a6c48c 100644 --- a/man/dataset_atom.Rd +++ b/man/dataset_atom.Rd @@ -35,9 +35,11 @@ be set as a default via an environment variable. To set a default, run or add \verb{DATAVERSE_SERVER = "dataverse.harvard.edu} in one's \code{.Renviron} file (\code{usethis::edit_r_environ()}), with the appropriate domain as its value.} -\item{...}{Additional arguments passed to an HTTP request function, such as -\code{\link[httr]{GET}}, \code{\link[httr]{POST}}, or -\code{\link[httr]{DELETE}}.} +\item{...}{Additional arguments passed to an HTTP request function, +such as \code{\link[httr]{GET}}, \code{\link[httr]{POST}}, or +\code{\link[httr]{DELETE}}. By default, HTTP requests use +values cached from previous identical calls. Use +\code{use_cache=FALSE} (or \code{Sys.setenv(DATAVERSE_USE_CACHE = FALSE)} if cached API calls are not desired.} } \value{ A list. For \code{dataset_atom}, an object of class \dQuote{dataset_atom}. diff --git a/man/dataset_versions.Rd b/man/dataset_versions.Rd index efd4a3e..f100269 100644 --- a/man/dataset_versions.Rd +++ b/man/dataset_versions.Rd @@ -29,9 +29,11 @@ be set as a default via an environment variable. To set a default, run or add \verb{DATAVERSE_SERVER = "dataverse.harvard.edu} in one's \code{.Renviron} file (\code{usethis::edit_r_environ()}), with the appropriate domain as its value.} -\item{...}{Additional arguments passed to an HTTP request function, such as -\code{\link[httr]{GET}}, \code{\link[httr]{POST}}, or -\code{\link[httr]{DELETE}}.} +\item{...}{Additional arguments passed to an HTTP request function, +such as \code{\link[httr]{GET}}, \code{\link[httr]{POST}}, or +\code{\link[httr]{DELETE}}. By default, HTTP requests use +values cached from previous identical calls. Use +\code{use_cache=FALSE} (or \code{Sys.setenv(DATAVERSE_USE_CACHE = FALSE)} if cached API calls are not desired.} } \value{ A list of class \dQuote{dataverse_dataset_version}. diff --git a/man/dataverse_metadata.Rd b/man/dataverse_metadata.Rd index edb5f5f..3ce78d0 100644 --- a/man/dataverse_metadata.Rd +++ b/man/dataverse_metadata.Rd @@ -27,9 +27,11 @@ be set as a default via an environment variable. To set a default, run or add \verb{DATAVERSE_SERVER = "dataverse.harvard.edu} in one's \code{.Renviron} file (\code{usethis::edit_r_environ()}), with the appropriate domain as its value.} -\item{...}{Additional arguments passed to an HTTP request function, such as -\code{\link[httr]{GET}}, \code{\link[httr]{POST}}, or -\code{\link[httr]{DELETE}}.} +\item{...}{Additional arguments passed to an HTTP request function, +such as \code{\link[httr]{GET}}, \code{\link[httr]{POST}}, or +\code{\link[httr]{DELETE}}. By default, HTTP requests use +values cached from previous identical calls. Use +\code{use_cache=FALSE} (or \code{Sys.setenv(DATAVERSE_USE_CACHE = FALSE)} if cached API calls are not desired.} } \value{ A list diff --git a/man/delete_dataset.Rd b/man/delete_dataset.Rd index a9bbeec..5f82699 100644 --- a/man/delete_dataset.Rd +++ b/man/delete_dataset.Rd @@ -29,9 +29,11 @@ be set as a default via an environment variable. To set a default, run or add \verb{DATAVERSE_SERVER = "dataverse.harvard.edu} in one's \code{.Renviron} file (\code{usethis::edit_r_environ()}), with the appropriate domain as its value.} -\item{...}{Additional arguments passed to an HTTP request function, such as -\code{\link[httr]{GET}}, \code{\link[httr]{POST}}, or -\code{\link[httr]{DELETE}}.} +\item{...}{Additional arguments passed to an HTTP request function, +such as \code{\link[httr]{GET}}, \code{\link[httr]{POST}}, or +\code{\link[httr]{DELETE}}. By default, HTTP requests use +values cached from previous identical calls. Use +\code{use_cache=FALSE} (or \code{Sys.setenv(DATAVERSE_USE_CACHE = FALSE)} if cached API calls are not desired.} } \value{ A logical. diff --git a/man/delete_dataverse.Rd b/man/delete_dataverse.Rd index 1992609..f7fbc34 100644 --- a/man/delete_dataverse.Rd +++ b/man/delete_dataverse.Rd @@ -27,9 +27,11 @@ be set as a default via an environment variable. To set a default, run or add \verb{DATAVERSE_SERVER = "dataverse.harvard.edu} in one's \code{.Renviron} file (\code{usethis::edit_r_environ()}), with the appropriate domain as its value.} -\item{...}{Additional arguments passed to an HTTP request function, such as -\code{\link[httr]{GET}}, \code{\link[httr]{POST}}, or -\code{\link[httr]{DELETE}}.} +\item{...}{Additional arguments passed to an HTTP request function, +such as \code{\link[httr]{GET}}, \code{\link[httr]{POST}}, or +\code{\link[httr]{DELETE}}. By default, HTTP requests use +values cached from previous identical calls. Use +\code{use_cache=FALSE} (or \code{Sys.setenv(DATAVERSE_USE_CACHE = FALSE)} if cached API calls are not desired.} } \value{ A logical. diff --git a/man/delete_file.Rd b/man/delete_file.Rd index 364fc45..5136fc8 100644 --- a/man/delete_file.Rd +++ b/man/delete_file.Rd @@ -27,9 +27,11 @@ be set as a default via an environment variable. To set a default, run or add \verb{DATAVERSE_SERVER = "dataverse.harvard.edu} in one's \code{.Renviron} file (\code{usethis::edit_r_environ()}), with the appropriate domain as its value.} -\item{...}{Additional arguments passed to an HTTP request function, such as -\code{\link[httr]{GET}}, \code{\link[httr]{POST}}, or -\code{\link[httr]{DELETE}}.} +\item{...}{Additional arguments passed to an HTTP request function, +such as \code{\link[httr]{GET}}, \code{\link[httr]{POST}}, or +\code{\link[httr]{DELETE}}. By default, HTTP requests use +values cached from previous identical calls. Use +\code{use_cache=FALSE} (or \code{Sys.setenv(DATAVERSE_USE_CACHE = FALSE)} if cached API calls are not desired.} } \value{ If successful, a logical \code{TRUE}, else possibly some information. diff --git a/man/delete_sword_dataset.Rd b/man/delete_sword_dataset.Rd index 04d9a39..fdb4afb 100644 --- a/man/delete_sword_dataset.Rd +++ b/man/delete_sword_dataset.Rd @@ -27,9 +27,11 @@ be set as a default via an environment variable. To set a default, run or add \verb{DATAVERSE_SERVER = "dataverse.harvard.edu} in one's \code{.Renviron} file (\code{usethis::edit_r_environ()}), with the appropriate domain as its value.} -\item{...}{Additional arguments passed to an HTTP request function, such as -\code{\link[httr]{GET}}, \code{\link[httr]{POST}}, or -\code{\link[httr]{DELETE}}.} +\item{...}{Additional arguments passed to an HTTP request function, +such as \code{\link[httr]{GET}}, \code{\link[httr]{POST}}, or +\code{\link[httr]{DELETE}}. By default, HTTP requests use +values cached from previous identical calls. Use +\code{use_cache=FALSE} (or \code{Sys.setenv(DATAVERSE_USE_CACHE = FALSE)} if cached API calls are not desired.} } \value{ If successful, a logical \code{TRUE}, else possibly some information. diff --git a/man/files.Rd b/man/files.Rd index 691ac3d..50d4369 100644 --- a/man/files.Rd +++ b/man/files.Rd @@ -99,9 +99,11 @@ available, download the original version instead of the ingested? If there was no ingested version, is set to NA. Note in \verb{get_dataframe_*}, \code{original} is set to FALSE by default. Either can be changed.} -\item{...}{Additional arguments passed to an HTTP request function, such as -\code{\link[httr]{GET}}, \code{\link[httr]{POST}}, or -\code{\link[httr]{DELETE}}.} +\item{...}{Additional arguments passed to an HTTP request function, +such as \code{\link[httr]{GET}}, \code{\link[httr]{POST}}, or +\code{\link[httr]{DELETE}}. By default, HTTP requests use +values cached from previous identical calls. Use +\code{use_cache=FALSE} (or \code{Sys.setenv(DATAVERSE_USE_CACHE = FALSE)} if cached API calls are not desired.} \item{filename}{Filename of the dataset, with file extension as shown in Dataverse (for example, if nlsw88.dta was the original but is displayed as the ingested diff --git a/man/get_dataset.Rd b/man/get_dataset.Rd index 9c574dd..6639519 100644 --- a/man/get_dataset.Rd +++ b/man/get_dataset.Rd @@ -51,9 +51,11 @@ be set as a default via an environment variable. To set a default, run or add \verb{DATAVERSE_SERVER = "dataverse.harvard.edu} in one's \code{.Renviron} file (\code{usethis::edit_r_environ()}), with the appropriate domain as its value.} -\item{...}{Additional arguments passed to an HTTP request function, such as -\code{\link[httr]{GET}}, \code{\link[httr]{POST}}, or -\code{\link[httr]{DELETE}}.} +\item{...}{Additional arguments passed to an HTTP request function, +such as \code{\link[httr]{GET}}, \code{\link[httr]{POST}}, or +\code{\link[httr]{DELETE}}. By default, HTTP requests use +values cached from previous identical calls. Use +\code{use_cache=FALSE} (or \code{Sys.setenv(DATAVERSE_USE_CACHE = FALSE)} if cached API calls are not desired.} \item{block}{A character string specifying a metadata block to retrieve. By default this is \dQuote{citation}. Other values may be available, depending diff --git a/man/get_dataverse.Rd b/man/get_dataverse.Rd index 5328de1..692b26b 100644 --- a/man/get_dataverse.Rd +++ b/man/get_dataverse.Rd @@ -38,9 +38,11 @@ file (\code{usethis::edit_r_environ()}), with the appropriate domain as its valu \item{check}{A logical indicating whether to check that the value of \code{dataverse} is actually a numeric} -\item{...}{Additional arguments passed to an HTTP request function, such as -\code{\link[httr]{GET}}, \code{\link[httr]{POST}}, or -\code{\link[httr]{DELETE}}.} +\item{...}{Additional arguments passed to an HTTP request function, +such as \code{\link[httr]{GET}}, \code{\link[httr]{POST}}, or +\code{\link[httr]{DELETE}}. By default, HTTP requests use +values cached from previous identical calls. Use +\code{use_cache=FALSE} (or \code{Sys.setenv(DATAVERSE_USE_CACHE = FALSE)} if cached API calls are not desired.} } \value{ A list of class \dQuote{dataverse}. diff --git a/man/get_facets.Rd b/man/get_facets.Rd index 0d0777c..a84677d 100644 --- a/man/get_facets.Rd +++ b/man/get_facets.Rd @@ -27,9 +27,11 @@ be set as a default via an environment variable. To set a default, run or add \verb{DATAVERSE_SERVER = "dataverse.harvard.edu} in one's \code{.Renviron} file (\code{usethis::edit_r_environ()}), with the appropriate domain as its value.} -\item{...}{Additional arguments passed to an HTTP request function, such as -\code{\link[httr]{GET}}, \code{\link[httr]{POST}}, or -\code{\link[httr]{DELETE}}.} +\item{...}{Additional arguments passed to an HTTP request function, +such as \code{\link[httr]{GET}}, \code{\link[httr]{POST}}, or +\code{\link[httr]{DELETE}}. By default, HTTP requests use +values cached from previous identical calls. Use +\code{use_cache=FALSE} (or \code{Sys.setenv(DATAVERSE_USE_CACHE = FALSE)} if cached API calls are not desired.} } \value{ A list. diff --git a/man/get_file_metadata.Rd b/man/get_file_metadata.Rd index 7bd737f..1e8acc9 100644 --- a/man/get_file_metadata.Rd +++ b/man/get_file_metadata.Rd @@ -40,9 +40,11 @@ be set as a default via an environment variable. To set a default, run or add \verb{DATAVERSE_SERVER = "dataverse.harvard.edu} in one's \code{.Renviron} file (\code{usethis::edit_r_environ()}), with the appropriate domain as its value.} -\item{...}{Additional arguments passed to an HTTP request function, such as -\code{\link[httr]{GET}}, \code{\link[httr]{POST}}, or -\code{\link[httr]{DELETE}}.} +\item{...}{Additional arguments passed to an HTTP request function, +such as \code{\link[httr]{GET}}, \code{\link[httr]{POST}}, or +\code{\link[httr]{DELETE}}. By default, HTTP requests use +values cached from previous identical calls. Use +\code{use_cache=FALSE} (or \code{Sys.setenv(DATAVERSE_USE_CACHE = FALSE)} if cached API calls are not desired.} } \value{ A character vector containing a DDI diff --git a/man/get_user_key.Rd b/man/get_user_key.Rd index aac73cc..81d26fc 100644 --- a/man/get_user_key.Rd +++ b/man/get_user_key.Rd @@ -13,9 +13,11 @@ get_user_key(user, password, server = Sys.getenv("DATAVERSE_SERVER"), ...) \item{server}{The Dataverse instance. See \code{get_file}.} -\item{...}{Additional arguments passed to an HTTP request function, such as -\code{\link[httr]{GET}}, \code{\link[httr]{POST}}, or -\code{\link[httr]{DELETE}}.} +\item{...}{Additional arguments passed to an HTTP request function, +such as \code{\link[httr]{GET}}, \code{\link[httr]{POST}}, or +\code{\link[httr]{DELETE}}. By default, HTTP requests use +values cached from previous identical calls. Use +\code{use_cache=FALSE} (or \code{Sys.setenv(DATAVERSE_USE_CACHE = FALSE)} if cached API calls are not desired.} } \value{ A list. diff --git a/man/initiate_sword_dataset.Rd b/man/initiate_sword_dataset.Rd index 0be765d..9c6b10d 100644 --- a/man/initiate_sword_dataset.Rd +++ b/man/initiate_sword_dataset.Rd @@ -30,9 +30,11 @@ be set as a default via an environment variable. To set a default, run or add \verb{DATAVERSE_SERVER = "dataverse.harvard.edu} in one's \code{.Renviron} file (\code{usethis::edit_r_environ()}), with the appropriate domain as its value.} -\item{...}{Additional arguments passed to an HTTP request function, such as -\code{\link[httr]{GET}}, \code{\link[httr]{POST}}, or -\code{\link[httr]{DELETE}}.} +\item{...}{Additional arguments passed to an HTTP request function, +such as \code{\link[httr]{GET}}, \code{\link[httr]{POST}}, or +\code{\link[httr]{DELETE}}. By default, HTTP requests use +values cached from previous identical calls. Use +\code{use_cache=FALSE} (or \code{Sys.setenv(DATAVERSE_USE_CACHE = FALSE)} if cached API calls are not desired.} } \value{ An object of class \dQuote{dataset_atom}. diff --git a/man/list_datasets.Rd b/man/list_datasets.Rd index e077c07..4adaf52 100644 --- a/man/list_datasets.Rd +++ b/man/list_datasets.Rd @@ -27,9 +27,11 @@ be set as a default via an environment variable. To set a default, run or add \verb{DATAVERSE_SERVER = "dataverse.harvard.edu} in one's \code{.Renviron} file (\code{usethis::edit_r_environ()}), with the appropriate domain as its value.} -\item{...}{Additional arguments passed to an HTTP request function, such as -\code{\link[httr]{GET}}, \code{\link[httr]{POST}}, or -\code{\link[httr]{DELETE}}.} +\item{...}{Additional arguments passed to an HTTP request function, +such as \code{\link[httr]{GET}}, \code{\link[httr]{POST}}, or +\code{\link[httr]{DELETE}}. By default, HTTP requests use +values cached from previous identical calls. Use +\code{use_cache=FALSE} (or \code{Sys.setenv(DATAVERSE_USE_CACHE = FALSE)} if cached API calls are not desired.} } \value{ A list. diff --git a/man/publish_dataset.Rd b/man/publish_dataset.Rd index 0271e99..54288d4 100644 --- a/man/publish_dataset.Rd +++ b/man/publish_dataset.Rd @@ -32,9 +32,11 @@ be set as a default via an environment variable. To set a default, run or add \verb{DATAVERSE_SERVER = "dataverse.harvard.edu} in one's \code{.Renviron} file (\code{usethis::edit_r_environ()}), with the appropriate domain as its value.} -\item{...}{Additional arguments passed to an HTTP request function, such as -\code{\link[httr]{GET}}, \code{\link[httr]{POST}}, or -\code{\link[httr]{DELETE}}.} +\item{...}{Additional arguments passed to an HTTP request function, +such as \code{\link[httr]{GET}}, \code{\link[httr]{POST}}, or +\code{\link[httr]{DELETE}}. By default, HTTP requests use +values cached from previous identical calls. Use +\code{use_cache=FALSE} (or \code{Sys.setenv(DATAVERSE_USE_CACHE = FALSE)} if cached API calls are not desired.} } \value{ A list. diff --git a/man/publish_dataverse.Rd b/man/publish_dataverse.Rd index 89e9c4f..5f643c0 100644 --- a/man/publish_dataverse.Rd +++ b/man/publish_dataverse.Rd @@ -27,9 +27,11 @@ be set as a default via an environment variable. To set a default, run or add \verb{DATAVERSE_SERVER = "dataverse.harvard.edu} in one's \code{.Renviron} file (\code{usethis::edit_r_environ()}), with the appropriate domain as its value.} -\item{...}{Additional arguments passed to an HTTP request function, such as -\code{\link[httr]{GET}}, \code{\link[httr]{POST}}, or -\code{\link[httr]{DELETE}}.} +\item{...}{Additional arguments passed to an HTTP request function, +such as \code{\link[httr]{GET}}, \code{\link[httr]{POST}}, or +\code{\link[httr]{DELETE}}. By default, HTTP requests use +values cached from previous identical calls. Use +\code{use_cache=FALSE} (or \code{Sys.setenv(DATAVERSE_USE_CACHE = FALSE)} if cached API calls are not desired.} } \value{ A list. diff --git a/man/publish_sword_dataset.Rd b/man/publish_sword_dataset.Rd index a4227e5..41a48d1 100644 --- a/man/publish_sword_dataset.Rd +++ b/man/publish_sword_dataset.Rd @@ -27,9 +27,11 @@ be set as a default via an environment variable. To set a default, run or add \verb{DATAVERSE_SERVER = "dataverse.harvard.edu} in one's \code{.Renviron} file (\code{usethis::edit_r_environ()}), with the appropriate domain as its value.} -\item{...}{Additional arguments passed to an HTTP request function, such as -\code{\link[httr]{GET}}, \code{\link[httr]{POST}}, or -\code{\link[httr]{DELETE}}.} +\item{...}{Additional arguments passed to an HTTP request function, +such as \code{\link[httr]{GET}}, \code{\link[httr]{POST}}, or +\code{\link[httr]{DELETE}}. By default, HTTP requests use +values cached from previous identical calls. Use +\code{use_cache=FALSE} (or \code{Sys.setenv(DATAVERSE_USE_CACHE = FALSE)} if cached API calls are not desired.} } \value{ A list. diff --git a/man/service_document.Rd b/man/service_document.Rd index 7751d96..0353ffc 100644 --- a/man/service_document.Rd +++ b/man/service_document.Rd @@ -24,9 +24,11 @@ be set as a default via an environment variable. To set a default, run or add \verb{DATAVERSE_SERVER = "dataverse.harvard.edu} in one's \code{.Renviron} file (\code{usethis::edit_r_environ()}), with the appropriate domain as its value.} -\item{...}{Additional arguments passed to an HTTP request function, such as -\code{\link[httr]{GET}}, \code{\link[httr]{POST}}, or -\code{\link[httr]{DELETE}}.} +\item{...}{Additional arguments passed to an HTTP request function, +such as \code{\link[httr]{GET}}, \code{\link[httr]{POST}}, or +\code{\link[httr]{DELETE}}. By default, HTTP requests use +values cached from previous identical calls. Use +\code{use_cache=FALSE} (or \code{Sys.setenv(DATAVERSE_USE_CACHE = FALSE)} if cached API calls are not desired.} } \value{ A list of class \dQuote{sword_service_document}, possibly with one or more \dQuote{sword_collection} entries. The latter are SWORD representations of a Dataverse. These can be passed to other SWORD API functions, e.g., for creating a new dataset. diff --git a/man/set_dataverse_metadata.Rd b/man/set_dataverse_metadata.Rd index 9876713..0e86d60 100644 --- a/man/set_dataverse_metadata.Rd +++ b/man/set_dataverse_metadata.Rd @@ -33,9 +33,11 @@ be set as a default via an environment variable. To set a default, run or add \verb{DATAVERSE_SERVER = "dataverse.harvard.edu} in one's \code{.Renviron} file (\code{usethis::edit_r_environ()}), with the appropriate domain as its value.} -\item{...}{Additional arguments passed to an HTTP request function, such as -\code{\link[httr]{GET}}, \code{\link[httr]{POST}}, or -\code{\link[httr]{DELETE}}.} +\item{...}{Additional arguments passed to an HTTP request function, +such as \code{\link[httr]{GET}}, \code{\link[httr]{POST}}, or +\code{\link[httr]{DELETE}}. By default, HTTP requests use +values cached from previous identical calls. Use +\code{use_cache=FALSE} (or \code{Sys.setenv(DATAVERSE_USE_CACHE = FALSE)} if cached API calls are not desired.} } \value{ A list diff --git a/tests/testthat.R b/tests/testthat.R index a5ae096..c520ba2 100644 --- a/tests/testthat.R +++ b/tests/testthat.R @@ -14,8 +14,11 @@ if (!requireNamespace("yaml", quietly = TRUE)) { config <- yaml::read_yaml(system.file("constants.yml", package = "dataverse")) # config <- yaml::read_yaml("inst/constants.yml") - Sys.setenv("DATAVERSE_SERVER" = config$server) - Sys.setenv("DATAVERSE_KEY" = config$api_token) + Sys.setenv( + DATAVERSE_SERVER = config$server, + DATAVERSE_KEY = config$api_token, + DATAVERSE_USE_CACHE = FALSE + ) # To better identify the source of problems, check if the token is expired. # This check *should* be unnecessary on CRAN, since not CRAN tests should