Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update to reflect updates to Zenodo API #91

Merged
merged 5 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,7 @@ importFrom(utils,globalVariables)
importFrom(utils,hasName)
importFrom(utils,packageVersion)
importFrom(utils,read.csv)
importFrom(xml2,xml_attr)
importFrom(xml2,xml_find_all)
importFrom(xml2,xml_find_first)
importFrom(xml2,xml_text)
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* More generous filename checks now pass files named e.g. "..._participants_common..." an not only "...participant_common..."
* The package now sets a custom user agent when downloading survey data (#82).
* A problem was fixed where attempted joins of files could lead to blowing up memeory use (#75).
* A problem was fixed where the updated Zenodo API caused downloading to fail (#91).

# socialmixr 0.2.0

Expand Down
15 changes: 9 additions & 6 deletions R/download_survey.r
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#' @importFrom jsonlite fromJSON toJSON
#' @importFrom curl curl_download
#' @importFrom utils read.csv packageVersion
#' @importFrom xml2 xml_text xml_find_first
#' @importFrom xml2 xml_text xml_find_first xml_find_all xml_attr
#' @autoglobal
#' @examples
#' \dontrun{
Expand Down Expand Up @@ -61,18 +61,21 @@ download_survey <- function(survey, dir = NULL) {
reference <- list(
title = parsed_cite$name,
bibtype = "Misc",
author = parsed_cite$creator$name,
author = parsed_cite$author$name,
year = data.table::year(parsed_cite$datePublished)
)
if ("version" %in% names(parsed_cite)) {
reference[["note"]] <- paste("Version", parsed_cite$version)
}
reference[[ifelse(is.doi, "doi", "url")]] <- survey

data <- data.table(parsed_cite$distribution)
links <- xml_attr(
xml_find_all(parsed_body, "//link[@type=\"text/csv\"]"), "href"
)

data <- data.table(url = links)
## only download csv files
data <- data[encodingFormat == "csv"]
data[, file_name := tolower(basename(contentUrl))]
data[, file_name := tolower(basename(url))]

if (anyDuplicated(data$file_name) > 0) {
warning(
Expand All @@ -95,7 +98,7 @@ download_survey <- function(survey, dir = NULL) {
write(reference_json, reference_file_path)

files <- c(reference_file_path, vapply(seq_len(nrow(data)), function(i) {
url <- data[i, ]$contentUrl
url <- data[i, ]$url
temp <- file.path(dir, data[i, ]$file_name)
message("Downloading ", url)
dl <- curl_download(url, temp)
Expand Down
2 changes: 0 additions & 2 deletions R/globals.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ utils::globalVariables(c(
"bootstrap.weight", # <contact_matrix>
"proportion", # <contact_matrix>
"participants", # <contact_matrix>
"encodingFormat", # <download_survey>
"file_name", # <download_survey>
"contentUrl", # <download_survey>
"common_doi", # <list_surveys>
"doi.nb", # <list_surveys>
"identifier.1", # <list_surveys>
Expand Down
1 change: 0 additions & 1 deletion tests/testthat/test-surveys.r
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ test_that("list of surveys is not empty", {
test_that("surveys can be downloaded", {
skip_if_offline("zenodo.org")
skip_on_cran()
skip_on_ci()

s <- suppressMessages(suppressWarnings(get_survey("10.5281/zenodo.1059920"))) # nolint

Expand Down
Loading