-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make get_aphia_id() a public function
- Loading branch information
1 parent
0ac198c
commit 02333a8
Showing
6 changed files
with
58 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#' Get AphiaID from a taxonomic name | ||
#' | ||
#' This function wraps [worrms::wm_name2id_()] so that it returns a data frame | ||
#' rather than a list. | ||
#' It also silences "not found" warnings, returning `NA` instead | ||
#' | ||
#' @param x A (vector with) taxonomic name(s). | ||
#' @return Data frame with `name` and `aphia_id`. | ||
#' @family support functions | ||
#' @importFrom dplyr %>% | ||
#' @export | ||
#' @examples | ||
#' get_aphia_id("Mola mola") | ||
#' get_aphia_id(c("Mola mola", "not_a_name")) | ||
get_aphia_id <- function(x) { | ||
result <- suppressWarnings(worrms::wm_name2id_(x)) | ||
taxa <- result %>% | ||
purrr::discard(is.list) %>% # Remove x$message: "Not found" for e.g. "?" | ||
dplyr::as_tibble() %>% | ||
tidyr::pivot_longer(cols = dplyr::everything()) %>% | ||
dplyr::rename(aphia_id = value) | ||
# Join resulting taxa (with aphia_id) and input names to get df with all names | ||
taxa %>% | ||
dplyr::full_join(dplyr::as_tibble(x), by = c("name" = "value")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.