Skip to content

Commit

Permalink
remove trailing whitespace
Browse files Browse the repository at this point in the history
  • Loading branch information
wibeasley committed Jan 3, 2020
1 parent b95d33a commit b7a511c
Show file tree
Hide file tree
Showing 28 changed files with 126 additions and 125 deletions.
8 changes: 4 additions & 4 deletions R/SWORD.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#' \dontrun{
#' # retrieve your service document
#' d <- service_document()
#'
#'
#' # list available datasets in first dataverse
#' list_datasets(d[[2]])
#' }
Expand Down Expand Up @@ -62,7 +62,7 @@ print.sword_service_document <- function(x, ...) {
#' \dontrun{
#' # retrieve your service document
#' d <- service_document()
#'
#'
#' # list available datasets in first dataverse
#' list_datasets(d[[2]])
#' }
Expand All @@ -77,13 +77,13 @@ list_datasets <- function(dataverse, key = Sys.getenv("DATAVERSE_KEY"), server =
u <- paste0(api_url(server, prefix="dvn/api/"), "data-deposit/v1.1/swordv2/collection/dataverse/", dataverse)
r <- httr::GET(u, httr::authenticate(key, ""), ...)
httr::stop_for_status(r)

# clean up response structure
x <- xml2::as_list(xml2::read_xml(r$content))
out <- list(title = x[["title"]][[1L]],
generator = x[["generator"]],
dataverseHasBeenReleased = x[["dataverseHasBeenReleased"]][[1L]])
out[["datasets"]] <- do.call("rbind.data.frame",
out[["datasets"]] <- do.call("rbind.data.frame",
lapply(x[which(names(x) == "entry")], function(ds) {
list(title = ds[["title"]][[1L]],
id = ds[["id"]][[1L]])
Expand Down
16 changes: 8 additions & 8 deletions R/SWORD_dataset.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#' \dontrun{
#' # retrieve your service document (dataverse list)
#' d <- service_document()
#'
#'
#' # create a list of metadata
#' metadat <- list(title = "My Study",
#' creator = "Doe, John",
Expand Down Expand Up @@ -76,15 +76,15 @@ initiate_sword_dataset <- function(dataverse, body, key = Sys.getenv("DATAVERSE_
#' \dontrun{
#' # retrieve your service document
#' d <- service_document()
#'
#'
#' # create a list of metadata
#' metadat <- list(title = "My Study",
#' creator = "Doe, John",
#' description = "An example study")
#'
#' # create the dataset in first dataverse
#' dat <- initiate_sword_dataset(d[[2]], body = metadat)
#'
#'
#' # delete a dataset
#' delete_dataset(dat)
#' }
Expand Down Expand Up @@ -128,18 +128,18 @@ delete_sword_dataset <- function(dataset, key = Sys.getenv("DATAVERSE_KEY"), ser
#' \dontrun{
#' # retrieve your service document
#' d <- service_document()
#'
#'
#' # create a list of metadata
#' metadat <- list(title = "My Study",
#' creator = "Doe, John",
#' description = "An example study")
#'
#' # create the dataset in first dataverse
#' dat <- initiate_sword_dataset(d[[2]], body = metadat)
#'
#'
#' # publish dataset
#' publish_sword_dataset(dat)
#'
#'
#' # delete a dataset
#' delete_dataset(dat)
#' }
Expand Down Expand Up @@ -180,10 +180,10 @@ publish_sword_dataset <- function(dataset, key = Sys.getenv("DATAVERSE_KEY"), se
#' \dontrun{
#' # retrieve your service document
#' d <- service_document()
#'
#'
#' # retrieve dataset statement (list contents)
#' dataset_statement(d[[2]])
#'
#'
#' # retrieve dataset atom
#' dataset_atom(d[[2]])
#' }
Expand Down
22 changes: 11 additions & 11 deletions R/SWORD_files.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ create_zip.list <- function(x, ...) {
#' @title Add file (SWORD)
#' @description Add one or more files to a SWORD (possibly unpublished) dataset
#' @details This function is used to add files to a dataset. It is part of the SWORD API, which is used to upload data to a Dataverse server. This means this can be used to view unpublished Dataverses and Datasets.
#'
#'
#' As of Dataverse v4.6.1, the \dQuote{native} API also provides endpoints to add and update files without going through the SWORD workflow. This functionality is provided by \code{\link{add_dataset_file}} and \code{\link{update_dataset_file}}.
#'
#'
#' @param dataset A dataset DOI (or other persistent identifier), an object of class \dQuote{dataset_atom} or \dQuote{dataset_statement}, or an appropriate and complete SWORD URL.
#' @param file A character vector of file names, a data.frame, or a list of R objects.
#' @template envvars
Expand All @@ -44,12 +44,12 @@ create_zip.list <- function(x, ...) {
#' \dontrun{
#' # retrieve your service document
#' d <- service_document()
#'
#'
#' # create a list of metadata
#' metadat <- list(title = "My Study",
#' creator = "Doe, John",
#' description = "An example study")
#'
#'
#' # create the dataset
#' dat <- initiate_sword_dataset("mydataverse", body = metadat)
#'
Expand All @@ -60,7 +60,7 @@ create_zip.list <- function(x, ...) {
#'
#' # publish dataset
#' publish_dataset(dat)
#'
#'
#' # delete a dataset
#' delete_dataset(dat)
#' }
Expand All @@ -84,8 +84,8 @@ add_file <- function(dataset, file, key = Sys.getenv("DATAVERSE_KEY"), server =

# file can be: a character vector of file names, a data.frame, or a list of R objects
file <- create_zip(file)
h <- httr::add_headers("Content-Disposition" = paste0("filename=", file),

h <- httr::add_headers("Content-Disposition" = paste0("filename=", file),
"Content-Type" = "application/zip",
"Packaging" = "http://purl.org/net/sword/package/SimpleZip")
r <- httr::POST(u, httr::authenticate(key, ""), h, body = httr::upload_file(file), ...)
Expand All @@ -105,24 +105,24 @@ add_file <- function(dataset, file, key = Sys.getenv("DATAVERSE_KEY"), server =
#' \dontrun{
#' # retrieve your service document
#' d <- service_document()
#'
#'
#' # create a list of metadata
#' metadat <- list(title = "My Study",
#' creator = "Doe, John",
#' description = "An example study")
#'
#'
#' # create the dataset
#' dat <- initiate_sword_dataset("mydataverse", body = metadat)
#'
#' # add files to dataset
#' tmp <- tempfile()
#' write.csv(iris, file = tmp)
#' f <- add_file(dat, file = tmp)
#'
#'
#' # delete a file
#' ds <- dataset_statement(dat)
#' delete_file(ds$files[[1]]$id
#'
#'
#' # delete a dataset
#' delete_dataset(dat)
#' }
Expand Down
56 changes: 28 additions & 28 deletions R/add_dataset_file.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
#' @title Add or update a file in a dataset
#' @description Add or update a file in a dataset
#' @details From Dataverse v4.6.1, the \dQuote{native} API provides endpoints to add and update files without going through the SWORD workflow. To use SWORD instead, see \code{\link{add_file}}. \code{add_dataset_file} adds a new file to a specified dataset.
#'
#'
#' \code{update_dataset_file} can be used to replace/update a published file. Note that it only works on published files, so unpublished drafts cannot be updated - the dataset must first either be published (\code{\link{publish_dataset}}) or deleted (\code{\link{delete_dataset}}).
#'
#'
#' @param file A character string
#' @template ds
#' @param 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 object of class \dQuote{dataverse_file} as returned by \code{\link{dataset_files}}.
Expand All @@ -21,40 +21,40 @@
#'
#' saveRDS(mtcars, tmp <- tempfile(fileext = ".rds"))
#' f <- add_dataset_file(tmp, dataset = ds, description = "mtcars")
#'
#'
#' # publish dataset
#' publish_dataset(ds)
#'
#' # update file and republish
#' saveRDS(iris, tmp)
#' update_dataset_file(tmp, dataset = ds, id = f,
#' update_dataset_file(tmp, dataset = ds, id = f,
#' description = "Actually iris")
#' publish_dataset(ds)
#'
#'
#' # cleanup
#' unlink(tmp)
#' delete_dataset(ds)
#' }
#' @export
add_dataset_file <-
function(file,
dataset,
description = NULL,
key = Sys.getenv("DATAVERSE_KEY"),
server = Sys.getenv("DATAVERSE_SERVER"),
add_dataset_file <-
function(file,
dataset,
description = NULL,
key = Sys.getenv("DATAVERSE_KEY"),
server = Sys.getenv("DATAVERSE_SERVER"),
...) {
dataset <- dataset_id(dataset, key = key, server = server, ...)

bod2 <- list()
if (!is.null(description)) {
bod2$description <- description
}
jsondata <- as.character(jsonlite::toJSON(bod2, auto_unbox = TRUE))

u <- paste0(api_url(server), "datasets/", dataset, "/add")
r <- httr::POST(u, httr::add_headers("X-Dataverse-key" = key), ...,
r <- httr::POST(u, httr::add_headers("X-Dataverse-key" = key), ...,
body = list(file = httr::upload_file(file),
jsonData = jsondata),
jsonData = jsondata),
encode = "multipart")
httr::stop_for_status(r)
out <- jsonlite::fromJSON(httr::content(r, "text", encoding = "UTF-8"))
Expand All @@ -63,17 +63,17 @@ function(file,

#' @rdname add_dataset_file
#' @export
update_dataset_file <-
function(file,
dataset = NULL,
id,
description = NULL,
force = TRUE,
key = Sys.getenv("DATAVERSE_KEY"),
server = Sys.getenv("DATAVERSE_SERVER"),
update_dataset_file <-
function(file,
dataset = NULL,
id,
description = NULL,
force = TRUE,
key = Sys.getenv("DATAVERSE_KEY"),
server = Sys.getenv("DATAVERSE_SERVER"),
...) {
dataset <- dataset_id(dataset, key = key, server = server, ...)

# get file ID from 'dataset'
if (!is.numeric(id)) {
if (inherits(id, "dataverse_file")) {
Expand All @@ -84,18 +84,18 @@ function(file,
id <- get_fileid(dataset, id, key = key, server = server, ...)
}
}

bod2 <- list(forceReplace = force)
if (!is.null(description)) {
bod2$description <- description
}
jsondata <- as.character(jsonlite::toJSON(bod2, auto_unbox = TRUE))

u <- paste0(api_url(server), "files/", id, "/replace")
r <- httr::POST(u, httr::add_headers("X-Dataverse-key" = key), ...,
r <- httr::POST(u, httr::add_headers("X-Dataverse-key" = key), ...,
body = list(file = httr::upload_file(file),
jsonData = jsondata
),
),
encode = "multipart")
httr::stop_for_status(r)
structure(jsonlite::fromJSON(httr::content(r, as = "text", encoding = "UTF-8"), simplifyDataFrame = FALSE)$data$files[[1L]], class = "dataverse_file")
Expand Down
4 changes: 2 additions & 2 deletions R/create_dataset.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
#' @title Create or update a dataset
#' @description Create or update dataset within a Dataverse
#' @details \code{create_dataset} creates a Dataverse dataset. In Dataverse, a \dQuote{dataset} is the lowest-level structure in which to organize files. For example, a Dataverse dataset might contain the files used to reproduce a published article, including data, analysis code, and related materials. Datasets can be organized into \dQuote{Dataverse} objects, which can be further nested within other Dataverses. For someone creating an archive, this would be the first step to producing said archive (after creating a Dataverse, if one does not already exist). Once files and metadata have been added, the dataset can be publised (i.e., made public) using \code{\link{publish_dataset}}.
#'
#'
#' \code{update_dataset} updates a Dataverse dataset that has already been created using \code{\link{create_dataset}}. This creates a draft version of the dataset or modifies the current draft if one is already in-progress. It does not assign a new version number to the dataset nor does it make it publicly visible (which can be done with \code{\link{publish_dataset}}).
#'
#'
#' @template dv
#' @template ds
#' @param body A list describing the dataset.
Expand Down
8 changes: 4 additions & 4 deletions R/create_dataverse.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#' @title Create Dataverse
#' @description Create a new Dataverse
#' @details This function can create a new Dataverse. In the language of Dataverse, a user has a \dQuote{root} Dataverse into which they can create further nested Dataverses and/or \dQuote{datasets} that contain, for example, a set of files for a specific project. Creating a new Dataverse can therefore be a useful way to organize other related Dataverses or sets of related datasets.
#'
#' @details This function can create a new Dataverse. In the language of Dataverse, a user has a \dQuote{root} Dataverse into which they can create further nested Dataverses and/or \dQuote{datasets} that contain, for example, a set of files for a specific project. Creating a new Dataverse can therefore be a useful way to organize other related Dataverses or sets of related datasets.
#'
#' For example, if one were involved in an ongoing project that generated monthly data. One may want to store each month's data and related files in a separate \dQuote{dataset}, so that each has its own persistent identifier (e.g., DOI), but keep all of these datasets within a named Dataverse so that the project's files are kept separate the user's personal Dataverse records. The flexible nesting of Dataverses allows for a number of possible organizational approaches.
#'
#'
#' @param dataverse A character string specifying a Dataverse name or an object of class \dQuote{dataverse}. If missing, a top-level Dataverse is created.
#' @template envvars
#' @template dots
Expand All @@ -12,7 +12,7 @@
#' @examples
#' \dontrun{
#' (dv <- create_dataverse("mydataverse"))
#'
#'
#' # cleanup
#' delete_dataverse("mydataverse")
#' }
Expand Down
2 changes: 1 addition & 1 deletion R/dataset_versions.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#' @seealso \code{\link{get_dataset}}, \code{\link{dataset_files}}, \code{\link{publish_dataset}}
#' @examples
#' \dontrun{
#' # download file from:
#' # download file from:
#' # https://dataverse.harvard.edu/dataset.xhtml?persistentId=doi:10.7910/DVN/ARKOTI
#' monogan <- get_dataverse("monogan")
#' monogan_data <- dataverse_contents(monogan)
Expand Down
16 changes: 8 additions & 8 deletions R/dataverse-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@
#' @details Dataverse is open-source data repository management software developed by the Institute for Quantitative Social Science at Harvard University. This package provides an R interface to Dataverse version 4 repositories, including the principal Dataverse hosted at Harvard (\url{https://dataverse.harvard.edu/}). Users can use the package to search for data stored in a Dataverse repository, retrieve data and other files, and also use the package to directly create and archive their own research data and software.
#'
#' A Dataverse is structured as a nested set of \dQuote{dataverse} repositories, such that a single dataverse can contain \dQuote{datasets} (a set of code files, data files, etc.) or other dataverses. Thus, users may want to search for dataverses (sets of dataverses and datasets), datasets (sets of files), or individual files, and retrieve those objects accordingly. To retrieve a given file, a user typically needs to know what dataset it is stored in. All datasets are identified by a persistent identifier (such as an DOI or Handle, depending on the age of the dataset and what Dataverse repository it is hosted in).
#'
#'
#' This package provides five main sets of functions to interact with Dataverse:
#'
#'
#' \itemize{
#' \item Search: \code{\link{dataverse_search}}
#' \item Data retrieval: \code{\link{get_dataverse}}, \code{\link{dataverse_contents}}, \code{\link{get_dataset}}, \code{\link{dataset_metadata}}, \code{\link{get_file}}
#' \item Data archiving (SWORD API): \code{\link{service_document}}, \code{\link{list_datasets}}, \code{\link{initiate_sword_dataset}}, \code{\link{delete_sword_dataset}}, \code{\link{publish_sword_dataset}}, \code{\link{add_file}}, \code{\link{delete_file}}
#' \item Dataverse management \dQuote{native} API: \code{\link{create_dataverse}}, \code{\link{publish_dataverse}}, \code{\link{delete_dataverse}}
#' \item Dataset management \dQuote{native} API: \code{\link{create_dataset}}, \code{\link{update_dataset}}, \code{\link{publish_dataset}}, \code{\link{delete_dataset}}, \code{\link{dataset_files}}, \code{\link{dataset_versions}}
#' }
#'
#' @references
#'
#' @references
#' \href{http://guides.dataverse.org/en/latest/api/index.html}{Dataverse API Documentation}
#'
#'
#' \href{http://dataverse.org/}{Dataverse Homepage}
#'
#'
#' \href{https://dataverse.harvard.edu/}{Harvard IQSS Dataverse}
#'
NULL
#'
NULL
2 changes: 1 addition & 1 deletion R/dataverse_metadata.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#' @seealso \code{\link{set_dataverse_metadata}}
#' @examples
#' \dontrun{
#' # download file from:
#' # download file from:
#' # https://dataverse.harvard.edu/dataset.xhtml?persistentId=doi:10.7910/DVN/ARKOTI
#' monogan <- get_dataverse("monogan")
#' monogan_data <- dataverse_contents(monogan)
Expand Down
Loading

0 comments on commit b7a511c

Please sign in to comment.