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

Inherit parsing issues #282

Merged
merged 19 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
6 changes: 5 additions & 1 deletion R/read_camtrap_dp.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ read_camtrap_dp <- function(file = NULL,
if (lifecycle::is_present(path) | (!is.null(file) && dir.exists(file))) {
lifecycle::deprecate_warn(
when = "0.6.0",
what = "read_camtrap_dp(path)",
what = "camtraptor::read_camtrap_dp(path)",
details = warning_detail
)
}
Expand Down Expand Up @@ -165,7 +165,11 @@ read_camtrap_dp <- function(file = NULL,
check_package(package, media = media)

# Inherit parsing issues from reading
attr(package$data$deployments, which = "problems") <- issues_deployments
attr(package$data$observations, which = "problems") <- issues_observations
if (media) {
attr(package$data$media, which = "problems") <- issues_media
}

return(package)
}
28 changes: 24 additions & 4 deletions tests/testthat/test-read_camtrap_dp.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,38 +49,58 @@ test_that("test warnings while reading files with parsing issues", {
"datapackage_for_parsing_issues.json",
package = "camtraptor"
)
w <- capture_warnings(
captured_warnings <- capture_warnings(
dp_issues <- camtraptor::read_camtrap_dp(file = camtrap_dp_file_with_issues)
damianooldoni marked this conversation as resolved.
Show resolved Hide resolved
)

# check number of warnings
expect_length(captured_warnings, 6)

# warning on deployments
expect_identical(
w[2], # w[1] is returned by readr via frictionless
captured_warnings[2], # captured_warnings[1] is returned by readr via frictionless
paste0(
"One or more parsing issues occurred while reading `deployments`. ",
"Check `?read_camtrap_dp()` for examples on how to use ",
"`readr::problems()`."
)
)

problems_deploys <- readr::problems(dp_issues$data$deployments)
expect_identical(nrow(problems_deploys), 2L)
expect_identical(problems_deploys$row, c(1L,2L))
expect_identical(problems_deploys$col, c(7L,7L))
expect_identical(problems_deploys$expected, rep("date like %Y-%m-%dT%H:%M:%S%z", 2))

# warning on observations
expect_identical(
w[4], # w[3] is returned by readr via frictionless
captured_warnings[4], # captured_warnings[3] is returned by readr via frictionless
paste0(
"One or more parsing issues occurred while reading `observations`. ",
"Check `?read_camtrap_dp()` for examples on how to use ",
"`readr::problems()`."
)
)
problems_obs <- readr::problems(dp_issues$data$observations)
expect_identical(nrow(problems_obs), 2L)
expect_identical(problems_obs$row, c(1L,2L))
expect_identical(problems_obs$col, c(5L,5L))
expect_identical(problems_obs$expected, rep("date like %Y-%m-%dT%H:%M:%S%z", 2))

# warning on media
expect_identical(
w[6], # w[5] is returned by readr via frictionless
captured_warnings[6], # captured_warnings[5] is returned by readr via frictionless
paste0(
"One or more parsing issues occurred while reading `media`. ",
"Check `?read_camtrap_dp()` for examples on how to use ",
"`readr::problems()`."
)
)
problems_media <- readr::problems(dp_issues$data$media)
expect_identical(nrow(problems_media), 1L)
expect_identical(problems_media$row, 2L)
expect_identical(problems_media$col, 5L)
expect_identical(problems_media$expected, "date like %Y-%m-%dT%H:%M:%S%z")
})

test_that("media is checked properly", {
Expand Down