From 697180e5b9bc0f6d7bc16068d45cd06cf25e2646 Mon Sep 17 00:00:00 2001 From: Will Beasley Date: Tue, 18 Feb 2020 23:49:26 -0600 Subject: [PATCH] test for `dataverse_contents()` ref #4 --- R/get_dataverse.R | 25 +++++++++++++++---- man/get_dataverse.Rd | 21 ++++++++++++---- tests/testthat/tests-dataverse_contents.R | 29 +++++++++++++++++++++++ 3 files changed, 65 insertions(+), 10 deletions(-) create mode 100644 tests/testthat/tests-dataverse_contents.R diff --git a/R/get_dataverse.R b/R/get_dataverse.R index d1b87eb..8c39b43 100644 --- a/R/get_dataverse.R +++ b/R/get_dataverse.R @@ -1,28 +1,43 @@ #' @rdname get_dataverse #' @title Get Dataverse #' @description Retrieve details of a Dataverse +#' #' @details \code{get_dataverse} function retrieves basic information about a Dataverse from a Dataverse server. To see the contents of the Dataverse, use \code{\link{dataverse_contents}} instead. Contents might include one or more \dQuote{datasets} and/or further Dataverses that themselves contain Dataverses and/or datasets. To view the file contents of a single Dataset, use \code{\link{get_dataset}}. +#' #' @template dv #' @template envvars #' @param check A logical indicating whether to check that the value of \code{dataverse} is actually a numeric #' @template dots #' @return A list of class \dQuote{dataverse}. +#' #' @examples #' \dontrun{ #' # view the root dataverse for a server #' get_dataverse(":root") #' dataverse_contents(":root") #' +#' Sys.setenv("DATAVERSE_SERVER" = "dataverse.harvard.edu") #' # download file from: #' # https://dataverse.harvard.edu/dataset.xhtml?persistentId=doi:10.7910/DVN/ARKOTI -#' monogan <- get_dataverse("monogan") -#' (monogan_data <- dataverse_contents(monogan)) +#' dv <- get_dataverse("monogan") +#' (contents <- dataverse_contents(dv)) #' #' # get a dataset from the dataverse -#' d1 <- get_dataset(monogan_data[[1]]) -#' f <- get_file(d1$files$datafile$id[3]) +#' d1 <- get_dataset(contents[[1]]) +#' f <- get_file(d1$files$id[3]) #' } -#' @seealso To manage Dataverses: \code{\link{create_dataverse}}, \code{\link{delete_dataverse}}, \code{\link{publish_dataverse}}, \code{\link{dataverse_contents}}; to get datasets: \code{\link{get_dataset}}; to search for Dataverses, datasets, or files: \code{\link{dataverse_search}} +#' @seealso To manage Dataverses: +#' \code{\link{create_dataverse}}, +#' \code{\link{delete_dataverse}}, +#' \code{\link{publish_dataverse}}, +#' \code{\link{dataverse_contents}}; +#' +#' To get datasets: +#' \code{\link{get_dataset}}; +#' +#' To search for Dataverses, datasets, or files: +#' \code{\link{dataverse_search}} +#' #' @export get_dataverse <- function(dataverse, key = Sys.getenv("DATAVERSE_KEY"), server = Sys.getenv("DATAVERSE_SERVER"), check = TRUE, ...) { if (isTRUE(check)) { diff --git a/man/get_dataverse.Rd b/man/get_dataverse.Rd index 676268c..58a10db 100644 --- a/man/get_dataverse.Rd +++ b/man/get_dataverse.Rd @@ -46,16 +46,27 @@ Retrieve details of a Dataverse get_dataverse(":root") dataverse_contents(":root") +Sys.setenv("DATAVERSE_SERVER" = "dataverse.harvard.edu") # download file from: # https://dataverse.harvard.edu/dataset.xhtml?persistentId=doi:10.7910/DVN/ARKOTI -monogan <- get_dataverse("monogan") -(monogan_data <- dataverse_contents(monogan)) +dv <- get_dataverse("monogan") +(contents <- dataverse_contents(dv)) # get a dataset from the dataverse -d1 <- get_dataset(monogan_data[[1]]) -f <- get_file(d1$files$datafile$id[3]) +d1 <- get_dataset(contents[[1]]) +f <- get_file(d1$files$id[3]) } } \seealso{ -To manage Dataverses: \code{\link{create_dataverse}}, \code{\link{delete_dataverse}}, \code{\link{publish_dataverse}}, \code{\link{dataverse_contents}}; to get datasets: \code{\link{get_dataset}}; to search for Dataverses, datasets, or files: \code{\link{dataverse_search}} +To manage Dataverses: +\code{\link{create_dataverse}}, +\code{\link{delete_dataverse}}, +\code{\link{publish_dataverse}}, +\code{\link{dataverse_contents}}; + +To get datasets: +\code{\link{get_dataset}}; + +To search for Dataverses, datasets, or files: +\code{\link{dataverse_search}} } diff --git a/tests/testthat/tests-dataverse_contents.R b/tests/testthat/tests-dataverse_contents.R new file mode 100644 index 0000000..317336c --- /dev/null +++ b/tests/testthat/tests-dataverse_contents.R @@ -0,0 +1,29 @@ +# See https://demo.dataverse.org/dataverse/dataverse-client-r + +test_that("dataverse root", { + expected_length_minimum <- 300 # 397 as of Feb 2020 + + dv <- get_dataverse(dataverse = ":root") + actual <- dataverse_contents(dv) + expect_gte(length(actual), expected_length_minimum) +}) + +test_that("dataverse for 'dataverse-client-r'", { + expected <- structure( + list( + id = 396356L, + identifier = "FK2/FAN622", + persistentUrl = "https://doi.org/10.70122/FK2/FAN622", + protocol = "doi", + authority = "10.70122", + publisher = "Demo Dataverse", + storageIdentifier = "file://10.70122/FK2/FAN622", + type = "dataset" + ), + class = "dataverse_dataset" + ) + + dv <- get_dataverse(dataverse = "dataverse-client-r") + actual <- dataverse_contents(dv) + expect_equal(actual[[1]], expected) +})