Skip to content
Open
Show file tree
Hide file tree
Changes from all 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: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: datawizard
Title: Easy Data Wrangling and Statistical Transformations
Version: 1.3.1
Version: 1.3.1.1
Authors@R: c(
person("Indrajeet", "Patil", , "patilindrajeet.science@gmail.com", role = "aut",
comment = c(ORCID = "0000-0003-1995-6531")),
Expand Down
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# datawizard (devel)

CHANGES

* `data_read()` now also reads zip-files from URLs (#682).

# datawizard 1.3.1

CHANGES
Expand Down
10 changes: 8 additions & 2 deletions R/data_read.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
#' or text files (like '.csv' files). All other file types are passed to
#' `rio::import()`. `data_write()` works in a similar way.
#'
#' @param path Character string, the file path to the data file.
#' @param path A character string specifying the path to the data file. This can
#' also be a URL.
#' @param path_catalog Character string, path to the catalog file. Only relevant
#' for SAS data files.
#' @param encoding The character encoding used for the file. Usually not needed.
Expand Down Expand Up @@ -50,7 +51,8 @@
#' inside zip-compressed files. Thus, `path` can also be a URL to a file like
#' `"http://www.url.com/file.csv"`. When `path` points to a zip-compressed file,
#' and there are multiple files inside the zip-archive, then the first supported
#' file is extracted and loaded.
#' file is extracted and loaded. It is also possible to read a zip-compressed
#' file from URLs.
#'
#' @section General behaviour:
#' `data_read()` detects the appropriate `read_*()` function based on the
Expand Down Expand Up @@ -176,6 +178,10 @@ data_read <- function(


.extract_zip <- function(path) {
# download from URL?
path <- .check_path_url(path, file_type = "zip")

# extract
files <- utils::unzip(path, list = TRUE)
files_ext <- vapply(files$Name, .file_ext, FUN.VALUE = character(1L))

Expand Down
2 changes: 1 addition & 1 deletion man/contr.deviation.Rd

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

6 changes: 4 additions & 2 deletions man/data_read.Rd

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

8 changes: 8 additions & 0 deletions tests/testthat/test-data_read.R
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,14 @@
)
expect_identical(sum(vapply(d, is.factor, FUN.VALUE = logical(1L))), 0L)
expect_identical(sum(vapply(d, is.numeric, FUN.VALUE = logical(1L))), 26L)

# directly dowload from zip
d <- data_read(
"https://raw.github.com/easystats/circus/main/data/EFC.zip",
verbose = FALSE
)
expect_identical(sum(vapply(d, is.factor, FUN.VALUE = logical(1L))), 15L)
expect_identical(sum(vapply(d, is.numeric, FUN.VALUE = logical(1L))), 11L)
})
})

Expand Down Expand Up @@ -577,7 +585,7 @@
httr::stop_for_status(request)
expect_message(
expect_message(
d <- data_read(

Check warning on line 588 in tests/testthat/test-data_read.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=tests/testthat/test-data_read.R,line=588,col=7,[implicit_assignment_linter] Avoid implicit assignments in function calls. For example, instead of `if (x <- 1L) { ... }`, write `x <- 1L; if (x) { ... }`.
# nolint
"https://raw.github.com/easystats/circus/main/data/model_object.rds",
verbose = TRUE
Expand Down
Loading