Skip to content

Commit

Permalink
test for dataverse_contents()
Browse files Browse the repository at this point in the history
ref #4
  • Loading branch information
wibeasley committed Feb 19, 2020
1 parent ffd786f commit 697180e
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 10 deletions.
25 changes: 20 additions & 5 deletions R/get_dataverse.R
Original file line number Diff line number Diff line change
@@ -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)) {
Expand Down
21 changes: 16 additions & 5 deletions man/get_dataverse.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions tests/testthat/tests-dataverse_contents.R
Original file line number Diff line number Diff line change
@@ -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)
})

0 comments on commit 697180e

Please sign in to comment.