Skip to content

Commit

Permalink
Merge pull request #133 from IQSS/dev
Browse files Browse the repository at this point in the history
For CRAN 0.3.14
  • Loading branch information
kuriwaki authored May 13, 2024
2 parents 67f74e8 + 720613b commit e1a55ea
Show file tree
Hide file tree
Showing 32 changed files with 675 additions and 144 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ man-roxygen/*
^README\.Rmd$
^README\.html$
^CONTRIBUTING\.md$
tests/.*_ghaction.R
^vignettes/figure$
^vignettes/figure/.+$
\.Rmd2$
Expand Down
12 changes: 10 additions & 2 deletions .github/workflows/R-CMD-check-daily.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
on:
schedule:
- cron: "20 3 * * *" # Run every morning at 3:20am UTC
# - cron: "7 1 * * *" # Run every morning at 1:07am UTC (~8pm central)

name: R-CMD-check-daily

Expand All @@ -13,9 +12,11 @@ jobs:
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: r-lib/actions/setup-r@v2
- uses: r-lib/actions/setup-r-dependencies@v2
with:
cache: "always"
- uses: r-lib/actions/setup-pandoc@v2

- name: Query dependencies
Expand Down Expand Up @@ -55,6 +56,13 @@ jobs:
rcmdcheck::rcmdcheck(args = c("--no-manual", "--as-cran"), error_on = "warning", check_dir = "check")
shell: Rscript {0}

- name: Test live dataverse in vignettes
run: |
devtools::load_all()
source("tests/B-search_ghaction.R")
source("tests/C-download_ghaction.R")
shell: Rscript {0}

- name: Test coverage
run: covr::codecov()
shell: Rscript {0}
35 changes: 16 additions & 19 deletions .github/workflows/R-CMD-check-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@ on:
push:
branches:
- dev
# - main
# - master
# pull_request:
# branches:
# - main
# - master
pull_request:
branches:
- main

name: R-CMD-check-dev

Expand All @@ -19,32 +16,32 @@ jobs:
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-r@v2
- uses: r-lib/actions/setup-r-dependencies@v2
- uses: r-lib/actions/setup-pandoc@v2
with:
cache: "always"

- name: Cache R packages
if: runner.os != 'Windows'
uses: actions/cache@v1
uses: actions/cache@v3
with:
path: ${{ env.R_LIBS_USER }}
key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }}
restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-

- name: Install system dependencies
if: runner.os == 'Linux'
env:
RHUB_PLATFORM: linux-x86_64-ubuntu-gcc
run: |
Rscript -e "remotes::install_github('r-hub/sysreqs')"
sysreqs=$(Rscript -e "cat(sysreqs::sysreq_commands('DESCRIPTION'))")
sudo -s eval "$sysreqs"
- name: Check
run: |
options(crayon.enabled = TRUE)
rcmdcheck::rcmdcheck(args = c("--no-manual", "--as-cran"), error_on = "warning", check_dir = "check")
rcmdcheck::rcmdcheck(args = c("--no-manual", "--as-cran"), error_on = "error", check_dir = "check")
shell: Rscript {0}

- name: Test live dataverse in vignettes
run: |
devtools::load_all()
source("tests/B-search_ghaction.R")
source("tests/C-download_ghaction.R")
shell: Rscript {0}

- name: Test coverage
Expand Down
18 changes: 10 additions & 8 deletions .github/workflows/R-CMD-check-thorough.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,9 @@
# For help debugging build failures open an issue on the RStudio community with the 'github-actions' tag.
# https://community.rstudio.com/new-topic?category=Package%20development&tags=github-actions
on:
push:
branches:
- main
- master
# - dev

pull_request:
branches:
- main
- master

name: R-CMD-check-thorough

Expand Down Expand Up @@ -43,7 +36,7 @@ jobs:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-r@v2
id: install-r
Expand All @@ -52,6 +45,8 @@ jobs:
http-user-agent: ${{ matrix.config.http-user-agent }}

- uses: r-lib/actions/setup-r-dependencies@v2
with:
cache: "always"
- uses: r-lib/actions/setup-pandoc@v2

- name: Restore R package cache
Expand Down Expand Up @@ -91,6 +86,13 @@ jobs:
rcmdcheck::rcmdcheck(args = c("--no-manual", "--as-cran"), error_on = "warning", check_dir = "check")
shell: Rscript {0}

- name: Test live dataverse in vignettes
run: |
devtools::load_all()
source("tests/B-search_ghaction.R")
source("tests/C-download_ghaction.R")
shell: Rscript {0}

- name: Show testthat output
if: always()
run: find check -name 'testthat.Rout*' -exec cat '{}' \; || true
Expand Down
11 changes: 8 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: dataverse
Version: 0.3.13
Version: 0.3.14
Title: Client for Dataverse 4+ Repositories
Authors@R:
c(person(given = "Shiro",
Expand Down Expand Up @@ -32,7 +32,12 @@ Authors@R:
role = "ctb"),
person(given = "Edward",
family = "Jee",
role = "ctb"))
role = "ctb"),
person(given = "Johannes",
family = "Gruber",
role = c("ctb"),
email = "[email protected]",
comment = c(ORCID = "0000-0001-9177-1772")))
Imports:
checkmate,
httr,
Expand All @@ -59,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.0
RoxygenNote: 7.2.3
Roxygen: list(markdown = TRUE)
Config/testthat/edition: 3
4 changes: 4 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ export(get_file_by_doi)
export(get_file_by_id)
export(get_file_by_name)
export(get_file_metadata)
export(get_url)
export(get_url_by_doi)
export(get_url_by_id)
export(get_url_by_name)
export(get_user_key)
export(initiate_sword_dataset)
export(list_datasets)
Expand Down
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# dataverse

# CHANGES in dataverse 0.3.14

* Improve recommendation for rdata loading (#107, #127)
* `get_file_by_*()` can now return the download URL to be used in external functions or programs, useful for large files (#128, implemented in #129 @JBGruber and @kuriwaki)
* Removes remote resource from vignette and move them to ghactions (#131)

# CHANGES in dataverse 0.3.12 and 0.3.13

* Update expired token (#123)
Expand Down
60 changes: 32 additions & 28 deletions R/add_dataset_file.R
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,17 @@
#' }
#' @export
add_dataset_file <-
function(file,
dataset,
description = NULL,
key = Sys.getenv("DATAVERSE_KEY"),
server = Sys.getenv("DATAVERSE_SERVER"),
...) {
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(forceReplace = force)
if (!is.null(description)) {
bod2$description <- description
bod2$description <- description
}
jsondata <- as.character(jsonlite::toJSON(bod2, auto_unbox = TRUE))

Expand All @@ -81,44 +81,48 @@ function(file,
httr::stop_for_status(r, task = httr::content(r)$message)
out <- jsonlite::fromJSON(httr::content(r, "text", encoding = "UTF-8"))
out$data$files$dataFile$id[1L]
}
}

#' @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"),
...) {
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")) {
id <- get_fileid(id, key = key, server = server)
} else if (is.null(dataset)) {
stop("When 'id' is a character string, dataset must be specified. Or, use a global fileid instead.")
} else {
id <- get_fileid(dataset, id, key = key, server = server, ...)
}
if (inherits(id, "dataverse_file")) {
id <- get_fileid(id, key = key, server = server)
} else if (is.null(dataset)) {
stop("When 'id' is a character string, dataset must be specified. Or, use a global fileid instead.")
} else {
id <- get_fileid(dataset, id, key = key, server = server, ...)
}
}

bod2 <- list(forceReplace = force)
if (!is.null(description)) {
bod2$description <- 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, task = httr::content(r)$message)
structure(jsonlite::fromJSON(httr::content(r, as = "text", encoding = "UTF-8"), simplifyDataFrame = FALSE)$data$files[[1L]], class = "dataverse_file")
}
structure(jsonlite::fromJSON(
httr::content(r, as = "text", encoding = "UTF-8"),
simplifyDataFrame = FALSE)$data$files[[1L]], class = "dataverse_file"
)
}
16 changes: 7 additions & 9 deletions R/get_dataframe.R
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,13 @@
#'
#' # 3. RData files are read in by `base::load()` but cannot be assigned to an
#' # object name. The following shows two possible ways to read in such files.
#' # First, the RData object can be loaded to the environment without object assignment.
#'
#' # First, without relying on `get_dataframe_*`, write as a binary file:
#' as_binary <- get_file_by_doi(
#' filedoi = "doi:10.70122/FK2/PPIAXE/5VPXKE",
#' server = "demo.dataverse.org")
#'
#' temp <- tempdir()
#' writeBin(as_binary, path(temp, "county.RData"))
#' load(path(temp, "county.RData"))
#' get_dataframe_by_doi(
#' filedoi = "10.70122/FK2/PPIAXE/X2FC5V",
#' server = "demo.dataverse.org",
#' original = TRUE,
#' .f = function(x) load(x, envir = .GlobalEnv))
#'
#' # If you are certain each RData contains only one object, one could define a
#' # custom function used in https://stackoverflow.com/a/34926943
Expand Down Expand Up @@ -151,7 +149,7 @@ get_dataframe_by_id <- function(
}

# READ raw data
raw <- get_file(file = fileid, original = original, ...)
raw <- get_file(file = fileid, original = original, return_url = FALSE, ...)

# save to temp and then read it in with supplied function
if (!is.null(.f)) {
Expand Down
4 changes: 4 additions & 0 deletions R/get_file.R
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ get_file <- function(
dataset = NULL,
format = c("original", "bundle"),
vars = NULL,
return_url = FALSE,
key = Sys.getenv("DATAVERSE_KEY"),
server = Sys.getenv("DATAVERSE_SERVER"),
original = TRUE,
Expand Down Expand Up @@ -124,6 +125,7 @@ get_file <- function(
key = key,
server = server,
original = original,
return_url = return_url,
...
)
}
Expand All @@ -148,6 +150,7 @@ get_file_by_name <- function(
dataset,
format = c("original", "bundle"),
vars = NULL,
return_url = FALSE,
key = Sys.getenv("DATAVERSE_KEY"),
server = Sys.getenv("DATAVERSE_SERVER"),
original = TRUE,
Expand All @@ -171,6 +174,7 @@ get_file_by_name <- function(
key = key,
server = server,
original = original,
return_url = return_url,
...
)
}
Loading

0 comments on commit e1a55ea

Please sign in to comment.