Skip to content
Merged
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
Expand Up @@ -46,4 +46,4 @@ Suggests:
Config/testthat/edition: 3
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
Config/roxygen2/version: 8.0.0
Config/roxygen2/version: 8.1.0
30 changes: 30 additions & 0 deletions R/downgrade_package.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#' Downgrade a Camera Trap Data Package to Data Package v1
#'
#' Packages, schemas and resources created with frictionless >=2.0.0 follow the
#' v2 specification of Data Package, while Camtrap DP follows v1.
#' This function downgrades a package and its resources to v1.
#'
#' @inheritParams print.camtrapdp
#' @returns Downgraded `x`.
#' @family helper functions
#' @noRd
downgrade_package <- function(x) {
# Downgrade descriptor
x$`$schema` <- NULL # Profile expected to be present

# Downgrade resources
for (resource_name in frictionless::resource_names(x)) {
resource <- frictionless::resource(x, resource_name)
if (frictionless::version(resource) != "1.0") {
# Set profile (after name and description). Note: also removes attributes
resource <- append(resource, list(profile = "tabular-data-resource"), 2)

# Remove $schema and type
resource$`$schema` <- NULL
resource$type <- NULL
frictionless::resource(x, resource_name) <- resource
}
}

return(x)
}
3 changes: 3 additions & 0 deletions R/write_camtrapdp.R
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ write_camtrapdp <- function(x, directory, ...) {
recursive = TRUE
)

# Downgrade to Data Package v1
x <- downgrade_package(x)

# Write files
frictionless::write_package(x, directory, ...)

Expand Down
4 changes: 3 additions & 1 deletion tests/testthat/test-write_camtrapdp.R
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,9 @@ test_that("write_camtrapdp() returns the expected datapackage.json for the
on.exit(unlink(temp_dir, recursive = TRUE))

# Adapt x$taxonomic and x$contributors to test for https://github.com/inbo/camtrapdp/issues/185
x <- x |>
x <- suppressMessages(
update_taxon(
x,
from = "Anas platyrhynchos",
to = list(
scientificName = "Anas platyrhynchos",
Expand All @@ -110,6 +111,7 @@ test_that("write_camtrapdp() returns the expected datapackage.json for the
vernacularNames.nld = "wilde eend" # Assigns NA for vernacularNames.eng
)
)
)
contributors(x) <- contributors(x) # Assigns NA for e.g. firstName of INBO
write_camtrapdp(x, temp_dir)

Expand Down
Loading