Skip to content

Commit

Permalink
Merge pull request #136 from mtmorgan/code-cleanup
Browse files Browse the repository at this point in the history
Code cleanup
  • Loading branch information
kuriwaki authored Oct 4, 2024
2 parents 8fe5184 + b73fab9 commit 9af128a
Show file tree
Hide file tree
Showing 43 changed files with 137 additions and 59 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/R-CMD-check-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ name: R-CMD-check-dev

jobs:
R-CMD-check-dev:
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
Expand Down
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,6 @@ URL: https://iqss.github.io/dataverse-client-r/, https://dataverse.org/, https:/
BugReports: https://github.com/iqss/dataverse-client-r/issues
VignetteBuilder: knitr
Encoding: UTF-8
RoxygenNote: 7.2.3
RoxygenNote: 7.3.2
Roxygen: list(markdown = TRUE)
Config/testthat/edition: 3
11 changes: 11 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Generated by roxygen2: do not edit by hand

S3method(create_zip,character)
S3method(create_zip,data.frame)
S3method(create_zip,list)
S3method(dataset_id,character)
S3method(dataset_id,dataverse_dataset)
S3method(dataset_id,default)
S3method(dataverse_id,character)
S3method(dataverse_id,dataverse)
S3method(get_fileid,character)
S3method(get_fileid,dataverse_file)
S3method(get_fileid,numeric)
S3method(print,dataset_atom)
S3method(print,dataset_statement)
S3method(print,dataverse)
Expand Down
3 changes: 3 additions & 0 deletions R/SWORD_files.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
create_zip <- function(x, ...) {
UseMethod("create_zip", x)
}
#' @export
create_zip.character <- function(x, ...) {
f <- file.exists(x)
if (any(!f)) {
Expand All @@ -11,6 +12,7 @@ create_zip.character <- function(x, ...) {
return(tmp)
}
}
#' @export
create_zip.data.frame <- function(x, ...) {
tmpdf <- tempfile(fileext = ".zip")
on.exit(file.remove(tmpdf), add = TRUE)
Expand All @@ -19,6 +21,7 @@ create_zip.data.frame <- function(x, ...) {
stopifnot(!utils::zip(tmp, tmpdf))
return(tmp)
}
#' @export
create_zip.list <- function(x, ...) {
tmpdf <- sapply(seq_along(x), tempfile(fileext = ".zip"))
on.exit(file.remove(tmpdf), add = TRUE)
Expand Down
3 changes: 1 addition & 2 deletions R/dataverse-package.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#' @docType package
#' @name dataverse
#' @title Client for Dataverse Repositories
#' @description Provides access to Dataverse 4+ APIs, enabling data search, retrieval, and deposit.
Expand Down Expand Up @@ -27,4 +26,4 @@
#'
#' \href{https://dataverse.harvard.edu/}{Harvard IQSS Dataverse}
#'
NULL
"_PACKAGE"
11 changes: 9 additions & 2 deletions R/print.R
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,17 @@ print.dataverse_dataset <- function(x, ...) {
cat("Release Date: ", x$releaseTime, "\n", sep = "")
}
if ("license" %in% names(x)) {
cat("License: ", x$license, "\n", sep = "")
if (is.list(x$license)) {
## Dataverse >= 5.10
license <- x$license$name
} else {
## legacy
license <- x$name
}
cat("License: ", license,"\n", sep = "")
}
if ("files" %in% names(x)) {
n <- length(x$files)
n <- NROW(x$files)
cat(n, ngettext(n, " File:", " Files:"), "\n", sep = "")
print(x$files[c("label", "version", "id", "contentType")])
}
Expand Down
8 changes: 8 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ dataverse_id <- function(x, ...) {
dataverse_id.default <- function(x, ...) {
x
}
#' @export
dataverse_id.character <- function(x, ...) {
get_dataverse(x, ..., check = FALSE)$id
}
#' @export
dataverse_id.dataverse <- function(x, ...) {
x$id
}
Expand All @@ -16,9 +18,11 @@ dataverse_id.dataverse <- function(x, ...) {
dataset_id <- function(x, ...) {
UseMethod("dataset_id", x)
}
#' @export
dataset_id.default <- function(x, ...) {
x
}
#' @export
dataset_id.character <- function(x, key = Sys.getenv("DATAVERSE_KEY"), server = Sys.getenv("DATAVERSE_SERVER"), ...) {
x <- prepend_doi(x)
u <- paste0(api_url(server), "datasets/:persistentId?persistentId=", x)
Expand All @@ -28,6 +32,7 @@ dataset_id.character <- function(x, key = Sys.getenv("DATAVERSE_KEY"), server =
})
jsonlite::fromJSON(httr::content(r, as = "text", encoding = "UTF-8"))[["data"]][["id"]]
}
#' @export
dataset_id.dataverse_dataset <- function(x, ...) {
x$id
}
Expand All @@ -37,6 +42,7 @@ get_fileid <- function(x, ...) {
UseMethod("get_fileid", x)
}

#' @export
get_fileid.numeric <- function(x, file, key = Sys.getenv("DATAVERSE_KEY"), server = Sys.getenv("DATAVERSE_SERVER"), ...) {
files <- dataset_files(x, key = key, server = server, ...)
ids <- unlist(lapply(files, function(x) x[["datafile"]][["id"]]))
Expand All @@ -57,6 +63,7 @@ get_fileid.numeric <- function(x, file, key = Sys.getenv("DATAVERSE_KEY"), serve
id
}

#' @export
get_fileid.character <- function(x, file, key = Sys.getenv("DATAVERSE_KEY"), server = Sys.getenv("DATAVERSE_SERVER"), ...) {
files <- dataset_files(prepend_doi(x), key = key, server = server, ...)
ids <- unlist(lapply(files, function(x) x[["dataFile"]][["id"]]))
Expand All @@ -77,6 +84,7 @@ get_fileid.character <- function(x, file, key = Sys.getenv("DATAVERSE_KEY"), ser
id
}

#' @export
get_fileid.dataverse_file <- function(x, ...) {
x[["dataFile"]][["id"]]
}
Expand Down
2 changes: 1 addition & 1 deletion man-roxygen/ds.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#' @param dataset A character specifying a persistent identification ID for a dataset,
#' for example `"doi:10.70122/FK2/HXJVJU"`. Alternatively, an object of class
#' for example `"10.70122/FK2/HXJVJU"`. Alternatively, an object of class
#' \dQuote{dataverse_dataset} obtained by `dataverse_contents()`.
2 changes: 1 addition & 1 deletion man-roxygen/envvars.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
#' most major. The server can be defined each time within a function, or it can
#' be set as a default via an environment variable. To set a default, run
#' `Sys.setenv("DATAVERSE_SERVER" = "dataverse.harvard.edu")`
#' or add `DATAVERSE_SERVER = "dataverse.harvard.edu` in one's `.Renviron`
#' or add `DATAVERSE_SERVER = "dataverse.harvard.edu"` in one's `.Renviron`
#' file (`usethis::edit_r_environ()`), with the appropriate domain as its value.
4 changes: 2 additions & 2 deletions man/URLs.Rd

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

4 changes: 2 additions & 2 deletions man/add_dataset_file.Rd

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

2 changes: 1 addition & 1 deletion man/add_file.Rd

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

4 changes: 2 additions & 2 deletions man/create_dataset.Rd

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

2 changes: 1 addition & 1 deletion man/create_dataverse.Rd

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

2 changes: 1 addition & 1 deletion man/dataset_atom.Rd

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

4 changes: 2 additions & 2 deletions man/dataset_versions.Rd

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

30 changes: 30 additions & 0 deletions man/dataverse.Rd

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

2 changes: 1 addition & 1 deletion man/dataverse_metadata.Rd

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

2 changes: 1 addition & 1 deletion man/dataverse_search.Rd

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

4 changes: 2 additions & 2 deletions man/delete_dataset.Rd

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

2 changes: 1 addition & 1 deletion man/delete_dataverse.Rd

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

2 changes: 1 addition & 1 deletion man/delete_file.Rd

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

2 changes: 1 addition & 1 deletion man/delete_sword_dataset.Rd

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

4 changes: 2 additions & 2 deletions man/files.Rd

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

4 changes: 2 additions & 2 deletions man/get_dataframe.Rd

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

Loading

0 comments on commit 9af128a

Please sign in to comment.