From cfa098cb70e8e70ab601672356b2c5de403ac311 Mon Sep 17 00:00:00 2001 From: Elizabeth Wenk Date: Fri, 3 Nov 2023 12:27:44 +1100 Subject: [PATCH] tweaks to functions --- R/build_align_taxon_names.R | 14 ++++++++++---- R/build_update_taxon_list.R | 3 +-- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/R/build_align_taxon_names.R b/R/build_align_taxon_names.R index 180e65b53..a2e87daa4 100644 --- a/R/build_align_taxon_names.R +++ b/R/build_align_taxon_names.R @@ -1,17 +1,23 @@ build_align_taxon_names <- function(austraits, dataset) { - library(APCalign) - library(traits.build) + resources <- APCalign::load_taxonomic_resources() names_to_align <- austraits$taxonomic_updates %>% dplyr::filter(stringr::str_detect(dataset_id, dataset)) %>% - dplyr::filter(!cleaned_name %in% resources$APC$canonical_name & !cleaned_name %in% resources$APNI$canonical_name) %>% + dplyr::filter(!aligned_name %in% resources$APC$canonical_name & !aligned_name %in% resources$APNI$canonical_name) %>% dplyr::filter(is.na(taxonomic_resolution)) %>% dplyr::distinct(original_name) names_aligned <- APCalign::align_taxa(original_name = names_to_align$original_name) %>% - dplyr::select(find = original_name, replace = aligned_name, reason = aligned_reason, taxonomic_resolution = taxon_rank) + dplyr::select(all_of(c("original_name", "aligned_name", "aligned_reason", "taxon_rank"))) %>% + dplyr::rename(all_of(c( + "find" = "original_name", + "replace" = "aligned_name", + "reason" = "aligned_reason", + "taxonomic_resolution" = "taxon_rank" + ))) traits.build::metadata_add_taxonomic_changes_list(dataset, names_aligned) + } diff --git a/R/build_update_taxon_list.R b/R/build_update_taxon_list.R index 6fb1d9a52..418753d55 100644 --- a/R/build_update_taxon_list.R +++ b/R/build_update_taxon_list.R @@ -24,13 +24,12 @@ build_update_taxon_list <- function(austraits, taxon_list, replace = FALSE) { rename(aligned_name = canonical_name, taxon_rank_APNI = taxon_rank) # List of taxa that are explicitly excluded in metadata - don't want these in the taxon_list - # These should now be being excluded from `taxonomic_updates` table during processing, but good to check + # These should be excluded from `taxonomic_updates` table during processing, but good to check excluded_in_metadata <- austraits$excluded_data %>% filter(error == "Observation excluded in metadata") %>% distinct(original_name) # Start with taxonomic_updates table, which is all original names, aligned names, by dataset all_taxa <- austraits$taxonomic_updates %>% - #filter(str_detect(aligned_name, "Cynochloris")) %>% ##temporary dplyr::select(dplyr::all_of(c("original_name", "aligned_name", "taxonomic_resolution"))) %>% # In case the same `original_name`, `aligned_name` combination occurs twice, but only once with `taxonomic_resolution` attached, arrange names, taxon_ranks dplyr::arrange(aligned_name, taxonomic_resolution) %>%