From a99fc67c1c3b10e7dfb863ea5986ea9ea0ab4b4d Mon Sep 17 00:00:00 2001 From: Will Cornwell Date: Wed, 31 Jul 2024 17:21:05 +1000 Subject: [PATCH] adding check on resources to all functions that need resources --- R/create_species_state_origin_matrix.R | 5 +++++ R/create_taxonomic_update_lookup.R | 5 +++++ R/match_taxa.R | 5 +++++ R/native_anywhere_in_australia.R | 5 +++++ 4 files changed, 20 insertions(+) diff --git a/R/create_species_state_origin_matrix.R b/R/create_species_state_origin_matrix.R index c3e20bac..a3d82d11 100644 --- a/R/create_species_state_origin_matrix.R +++ b/R/create_species_state_origin_matrix.R @@ -27,6 +27,11 @@ #' #' create_species_state_origin_matrix <- function(resources = load_taxonomic_resources()) { + if(is.null(resources)){ + message("Not finding taxonomic resources; check internet connection?") + return(NULL) + } + apc_species <- filter_data_to_accepted_species(resources) sep_state_data <- separate_states(apc_species) apc_places <- identify_places(sep_state_data) diff --git a/R/create_taxonomic_update_lookup.R b/R/create_taxonomic_update_lookup.R index 0b3d3349..b9444913 100644 --- a/R/create_taxonomic_update_lookup.R +++ b/R/create_taxonomic_update_lookup.R @@ -170,6 +170,11 @@ create_taxonomic_update_lookup <- function(taxa, resources = load_taxonomic_resources(), quiet = FALSE, output = NULL) { + + if(is.null(resources)){ + message("Not finding taxonomic resources; check internet connection?") + return(NULL) + } validate_taxonomic_splits_input(taxonomic_splits) diff --git a/R/match_taxa.R b/R/match_taxa.R index d7050765..0914eaf5 100644 --- a/R/match_taxa.R +++ b/R/match_taxa.R @@ -53,6 +53,11 @@ match_taxa <- function( identifier = NA_character_ ) { + if(is.null(resources)){ + message("Not finding taxonomic resources; check internet connection?") + return(NULL) + } + update_na_with <- function(current, new) { ifelse(is.na(current), new, current) } diff --git a/R/native_anywhere_in_australia.R b/R/native_anywhere_in_australia.R index cd7aba60..dbd119f1 100644 --- a/R/native_anywhere_in_australia.R +++ b/R/native_anywhere_in_australia.R @@ -32,6 +32,11 @@ native_anywhere_in_australia <- function(species, resources = load_taxonomic_res # Create lookup tables full_lookup <- create_species_state_origin_matrix(resources = resources) + if(is.null(resources)){ + message("Not finding taxonomic resources; check internet connection?") + return(NULL) + } + if (any(!species %in% full_lookup$species)) { warning("At least one input not found in APC; make sure inputs are at the species level and consider using `create_taxonomic_update_lookup` first.") }