Adds a subspecies column within taxonomic results (e.g. from make_galah_taxonomy or make_gbif_taxonomy). Simultaneously creates a rank_adj column that relevels any rank below subspecies to subspecies (i.e. any rank = form or variety will have rank_adj = subspecies)

make_subspecies_col(
  tax_res,
  use_levels = levels(envClean::lurank$rank),
  remove_strings = "\\s\\(.*\\)\\s"
)

Arguments

tax_res

Dataframe. Probably from call to galah::search_taxa()

use_levels

Ordered factor. Ideally with a match for each unique rank in tax_res

remove_brackets

Character. Vector of regex to remove from scientific_name before creating the subspecies column

Value

tax_res with extra columns subspecies and rank_adj. rank will be an ordered factor.

Examples

taxa <- c("Acacia lanigera", "Acacia lanigera var. gracilipes", "Spyridium glabrisepalum", "Spyridium eriocephalum var. glabrisepalum")
taxonomy_result <- galah::search_taxa(taxa)
#> Error in check_pour_package(.pkg): No data stored by `potions`
#>  try using `brew()
make_subspecies_col(taxonomy_result) |> dplyr::select(search_term, species, subspecies, rank, rank_adj)
#> Error: object 'taxonomy_result' not found