Skip to content

Commit

Permalink
Deprecate get_species()
Browse files Browse the repository at this point in the history
Fix #343
  • Loading branch information
damianooldoni committed Oct 30, 2024
1 parent 7e577e3 commit 418eca4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 64 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ This is a major release that updates the internal data model to Camtrap DP 1.0 a
- `read_camtrap_dp()` (with underscore) is now deprecated. Use `read_camtrapdp()`, which reexports the read functionality from [camtrapdp](https://inbo.github.io/camtrapdp/reference/read_camtrapdp.html) (#298) (#298).
- Function `get_record_table()` is now deprecated. Use `camtrapR_recordTable()` (#240).
- Function `get_cam_op()` is now deprecated. Use `camtrapR_cameraOperation()` (#239).
- Function `get_species()` is now deprecated. Use `taxa()` (#343).
- Function `get_n_species()` is now deprecated. Use `n_species()` (#243).
- Function `map_dep()` is now deprecated. Use `map_deployments()` (#231).
- Filter predicates (`apply_filter_predicate()`, `pred()` `pred_not()` `pred_gt()`, `pred_and()`, `pred_or()`, etc.) are now defunct. Use `filter_deployments()` (#316).
Expand Down
50 changes: 11 additions & 39 deletions R/get_species.R
Original file line number Diff line number Diff line change
@@ -1,45 +1,17 @@
#' Get species
#'
#' Gets all identified species.
#' @description
#' `r lifecycle::badge("deprecated")`
#'
#' This function is deprecated. Please use [taxa()] instead.
#'
#' @param x Camera trap data package object, as returned by
#' [camtrapdp::read_camtrapdp()].
#' @return A tibble data frame with all scientific names and vernacular names of
#' the identified species.
#' @family exploration functions
#' @inheritParams taxa
#' @export
#' @examples
#' x <- example_dataset()
#' get_species(x)
get_species <- function(x) {
# Get taxonomic information from metadata
if (!"taxonomic" %in% names(x)) {
return(NULL)
} else {
taxonomy <- x$taxonomic
if ("vernacularNames" %in% names(taxonomy[[1]])) {
# Get all languages used in vernacularNames
langs <- purrr::map(taxonomy, function(x) {
vernacular_languages <- NULL
if ("vernacularNames" %in% names(x)) {
vernacular_languages <- names(x$vernacularNames)
}
})
langs <- unique(unlist(langs))

# Fill empty vernacular names with NA
taxonomy <- purrr::map(taxonomy, function(x) {
missing_langs <- langs[!langs %in% names(x$vernacularNames)]
for (i in missing_langs) {
x$vernacularNames[[i]] <- NA_character_
}
x
})
}
# flatten list and transform to data.frame
purrr::map_dfr(taxonomy, function(x) {
purrr::list_flatten(x, name_spec = "{outer}.{inner}")
}
)
}
lifecycle::deprecate_warn(
when = "1.0.0",
what = "get_species()",
with = "taxa()"
)
taxa(x)
}
28 changes: 3 additions & 25 deletions man/get_species.Rd

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

0 comments on commit 418eca4

Please sign in to comment.