From b9af2d874c182d0617bdb01a6c3e6b4cab60145e Mon Sep 17 00:00:00 2001 From: Daniel Falster Date: Wed, 26 Jul 2023 12:59:56 +1000 Subject: [PATCH] Reducing duplication --- R/clean_names.R | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/R/clean_names.R b/R/clean_names.R index b0d7705f..6c286dd6 100644 --- a/R/clean_names.R +++ b/R/clean_names.R @@ -569,24 +569,19 @@ get_updated_species_list <- aligned_data$aligned_name %>% update_taxonomy(resources = resources, output = output) if (one_to_many %in% c("return_all", "collapse_to_higher_taxon")) { - aligned_data %>% - dplyr::select(original_name, aligned_name, aligned_reason) %>% - dplyr::left_join(aligned_species_list_tmp, - by = c("aligned_name"), - multiple = "all") %>% - dplyr::filter(!is.na(taxonIDClean)) %>% - dplyr::mutate(genus = stringr::word(canonicalName, 1, 1)) %>% - dplyr::rename(canonical_name = canonicalName) + multiple = "all" } else { - aligned_data %>% - dplyr::select(original_name, aligned_name, aligned_reason) %>% - dplyr::left_join(aligned_species_list_tmp, - by = c("aligned_name"), - multiple = "first") %>% - dplyr::filter(!is.na(taxonIDClean)) %>% - dplyr::mutate(genus = stringr::word(canonicalName, 1, 1)) %>% - dplyr::rename(canonical_name = canonicalName) + multiple = "first" } + + aligned_data %>% + dplyr::select(original_name, aligned_name, aligned_reason) %>% + dplyr::left_join(aligned_species_list_tmp, + by = c("aligned_name"), + multiple = multiple) %>% + dplyr::filter(!is.na(taxonIDClean)) %>% + dplyr::mutate(genus = stringr::word(canonicalName, 1, 1)) %>% + dplyr::rename(canonical_name = canonicalName) }