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)
RoxygenNote: 7.3.2
RoxygenNote: 7.3.3
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# camtrapdp (development version)

* `read_camtrapdp()` now upgrades datasets to Camtrap DP 1.0.2 (#183).
* `read_camtrapdp()` now upgrades datasets to Camtrap DP 1.0.2 (#183) and provides help for unsupported versions.
* `write_camtrapdp()` now removes properties with `NA` values from `x$taxonomic` and `x$contributors` which caused `datapackage.json` to be invalid (#186).
* `write_eml()`'s derived paragraph is now formatted as DocBook rather than HTML (#188).

Expand Down
9 changes: 7 additions & 2 deletions R/read_camtrapdp.R
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,16 @@ read_camtrapdp <- function(file) {
# Check version
version <- version(package)
supported_versions <- c("1.0", "1.0.1", "1.0.2")
camtrapdp_version <- utils::packageVersion("camtrapdp")
if (!version %in% supported_versions) {
cli::cli_abort(
c(
"{.val {version}} is not a supported Camtrap DP version.",
"i" = "Supported version{?s}: {.val {supported_versions}}."
"Can't read a dataset that is referencing Camtrap DP version
{.val {version}}.",
"i" = "Supported Camtrap DP version{?s}: {.val {supported_versions}}.",
"i" = "You currently use {.pkg camtrapdp} {.val {camtrapdp_version}}.
Updating to the latest version with {.code
install.packages(\"camtrapdp\")} might resolve this error."
),
class = "camtrapdp_error_unsupported_version"
)
Expand Down
2 changes: 1 addition & 1 deletion R/round_coordinates.R
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ round_coordinates <- function(x, digits) {
original_digits <-
deployments(x) %>%
dplyr::mutate(
lat_digits = nchar(gsub("^\\d*.", "", .data$latitude))
lat_digits = nchar(stringr::str_remove(.data$latitude, "^\\d*\\."))
) %>%
dplyr::summarize(max(.data$lat_digits)) %>%
dplyr::pull()
Expand Down
2 changes: 1 addition & 1 deletion R/taxa.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ taxa <- function(x) {
dplyr::filter(!is.na(.data$scientificName)) %>%
dplyr::select("scientificName", dplyr::starts_with("taxon.")) %>%
dplyr::distinct() %>%
dplyr::rename_with(~ sub("^taxon.", "", .x)) %>%
dplyr::rename_with(~ stringr::str_remove(.x, "^taxon\\.")) %>%
dplyr::arrange(.data$scientificName)

# Remove duplicates without taxonID
Expand Down
2 changes: 1 addition & 1 deletion R/update_metadata.R
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ update_taxonomic <- function(x) {
vernacularNames <-
current_row %>%
dplyr::select(dplyr::starts_with("vernacularNames")) %>%
dplyr::rename_with(~ sub("^vernacularNames.", "", .x)) %>%
dplyr::rename_with(~ stringr::str_remove(.x, "^vernacularNames\\.")) %>%
as.list()

# Append to taxonomic list
Expand Down
9 changes: 5 additions & 4 deletions R/version.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ version <- function(x) {
match <- grep(pattern, profile)
if (length(match) > 0) {
extracted_version <- regmatches(profile, regexpr(pattern, profile))
extracted_version <- sub("camtrap-dp/", "", extracted_version, fixed = TRUE)
extracted_version <- sub("/", "", extracted_version, fixed = TRUE)
extracted_version <- stringr::str_remove(extracted_version, "camtrap-dp/")
extracted_version <- stringr::str_remove(extracted_version, "/")
extracted_version
} else {
profile
Expand All @@ -52,13 +52,14 @@ version <- function(x) {
new <- value

# Update profile
x$profile <- sub(old, new, x$profile, fixed = TRUE)
x$profile <- stringr::str_replace(x$profile, old, new)

# Update resource schemas
resource_names <- c("deployments", "media", "observations")
x$resources <- purrr::map(x$resources, function(resource) {
if (resource$name %in% resource_names) {
resource$schema <- sub(old, new, resource$schema, fixed = TRUE)
resource$schema <-
stringr::str_replace(resource$schema, old, new)
}
resource
})
Expand Down
2 changes: 1 addition & 1 deletion man/camtrapdp-package.Rd

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

10 changes: 5 additions & 5 deletions tests/testthat/helper.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
#' )
#' remove_uuid(to_clean)
remove_uuid <- function(character, replacement = "RANDOM_UUID") {
gsub(
"[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}", # nolint: line_length_linter
replacement,
character
stringr::str_replace_all(
character,
"[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}",
replacement
)
}

Expand Down Expand Up @@ -59,7 +59,7 @@ expect_meta_match <- function(file, core = "occurrence.csv", ...) {
csv_file_cols <-
readr::read_csv(file, show_col_types = FALSE) %>%
colnames() %>%
purrr::map_chr(~ sub("^[A-Za-z]+:", "", .x)) # Remove namespace like "dcterms:"
purrr::map_chr(~ stringr::str_remove(.x, "^[A-Za-z]+:")) # Remove namespace like "dcterms:"
csv_file_fields <-
dplyr::tibble(field = csv_file_cols) %>%
dplyr::mutate(index = as.integer(rownames(.)) - 1, .before = field) # Add index
Expand Down
8 changes: 6 additions & 2 deletions tests/testthat/test-round_coordinates.R
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ test_that("round_coordinates() updates spatial scope in metadata", {
x1 <- round_coordinates(x, 1)

# The number of digits in spatial scope is updated
expect_equal(max(nchar(gsub("^\\d*.", "", x2$spatial$coordinates))), 2)
expect_equal(max(nchar(gsub("^\\d*.", "", x1$spatial$coordinates))), 1)
expect_equal(max(stringr::str_length(
stringr::str_remove(x2$spatial$coordinates, "^\\d*\\.")
)), 2)
expect_equal(max(stringr::str_length(
stringr::str_remove(x1$spatial$coordinates, "^\\d*\\.")
)), 1)
})