Skip to content

Help users of filter_ functions with renamed Camtrap DP columns #191

@peterdesmet

Description

@peterdesmet

Note for self: In future versions of Camtrap DP, columns might get renamed (e.g. cameraHeight -> deviceHeight).

  • 👍 The upgrade() function (called by read_camtrapdp()) will automatically rename columns to the latest version of Camtrap DP.
  • 👎 Users providing old names in the filter_ functions will get an error (column not found). This will be especially confusing because the old column name still exists in their files on disk.

We should therefore warn users + rename the columns in the filter functions, so the behaviour is this:

library(camtrapdp)
x <- read_camtrapdp("http://raw.githubusercontent.com/tdwg/camtrap-dp/1.0/example/datapackage.json")

filter_deployments(x, cameraHeight >= 1.0)
#> Warning: cameraHeight has been renamed to deviceHeight. Please update your filter.
#> 
#> A Camera Trap Data Package "camtrap-dp-example-dataset" with 3 tables:
#> • deployments: 2 rows
#> • media: 240 rows
#> • observations: 339 rows
#> 
#> And 1 additional resource:
#> • individuals

To capture the ... of filter_deployments(), convert it to a vector to rename values and convert it back to ... use rlang::quos() and !!!. See:

camtrapdp/R/utils.R

Lines 17 to 21 in e465370

mutate_if_missing <- function(.data, ...) {
args <- rlang::quos(...)
new_columns <- args[!names(args) %in% colnames(.data)]
dplyr::mutate(.data, !!!new_columns)
}

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions