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

Add dl_read_d1_data() function #93

Closed
wants to merge 1 commit into from
Closed
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: 2 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
^.*\.Rproj$
^\.Rproj\.user$
^\.travis\.yml$
^LICENSE$
^inst/Pres$
33 changes: 24 additions & 9 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,32 @@ Authors@R: c(
person("Irene", "Steves", comment = "https://github.com/isteves", role = "aut"),
person("Mitchell", "Maier", email = "[email protected]", role = "aut"))
Maintainer: Julien Brun <[email protected]>
Description: Tools to download data and metadata from DataONE (https://www.dataone.org) and load this information in R.
Description: Tools to download data and metadata from DataONE (https://www.dataone.org) and load this information in R.
License: Apache License (== 2.0)
RoxygenNote: 6.1.1
Imports: dataone, dplyr, eml2, emld, lubridate, purrr, readr, stats, stringr, tibble, tidyr
Remotes: cboettig/eml2,
cboettig/emld,
DataONEorg/rdataone
Suggests: testthat,
URL: https://github.com/nceas/metajam
BugReports: https://github.com/nceas/metajam/issues
Encoding: UTF-8
Imports:
dataone,
dplyr,
eml2,
emld,
lubridate,
purrr,
readr,
stats,
stringr,
tibble,
tidyr
Remotes:
cboettig/eml2,
cboettig/emld,
DataONEorg/rdataone
Suggests:
testthat,
knitr,
rmarkdown,
udunits2
VignetteBuilder: knitr
URL: https://github.com/nceas/metajam
BugReports: https://github.com/nceas/metajam/issues
Roxygen: list(markdown = TRUE)
RoxygenNote: 6.1.1
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Generated by roxygen2: do not edit by hand

export(check_version)
export(dl_read_d1_data)
export(download_d1_data)
export(download_d1_data_pkg)
export(read_d1_files)
Expand Down
29 changes: 29 additions & 0 deletions R/dl_read_d1_data.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#' Download and read data along with metadata into your R environment
#'
#' This is a convenience function to both download and read data and metadata
#' into your R environment.
#'
#' @param data_url (character) An identifier or URL for a DataONE object to download.
#' @param path (character) Path to a directory to download data to.
#' @param fnc (character) Function to be used to read the data (default is `readr::read_csv()`).
#' @param ... Parameters to pass onto the function specified in `fnc`.
#'
#' @return (list) A named list containing data and metadata as data.frames.
#'
#' @export
#'
#' @seealso [download_d1_data()] [read_d1_files()]
#'
#' @examples
#' \dontrun{
#' dl_read_d1_data("urn:uuid:a2834e3e-f453-4c2b-8343-99477662b570", path = "./Data")
#' }

dl_read_d1_data <- function(data_url, path, fnc = "read_csv", ...) {
stopifnot(is.character(data_url) & nchar(data_url) > 0)
stopifnot(is.character(path) & nchar(path) > 0 & dir.exists(path))

dir <- download_d1_data(data_url, path)

read_d1_files(dir, fnc = "read_csv", ...)
}
2 changes: 1 addition & 1 deletion R/download_d1_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ download_d1_data <- function(data_url, path) {
purrr::map_chr(.x$physical$distribution$online$url, utils::URLdecode))))

if (length(entity_data) == 0) {
warning("No data metadata could not be found for ", data_url)
warning("No data metadata could be found for ", data_url)

} else {

Expand Down
32 changes: 32 additions & 0 deletions man/dl_read_d1_data.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/tabularize_eml.Rd

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

9 changes: 9 additions & 0 deletions tests/testthat/test-dl_read_d1_data.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
context("dl_read_d1_data()")

test_that("correct inputs are given", {
expect_error(dl_read_d1_data(7, 7))
expect_error(dl_read_d1_data("", 7))
expect_error(dl_read_d1_data("", ""))
expect_error(dl_read_d1_data("test", ""))
expect_error(dl_read_d1_data("test", "test"))
})