From 005e3d3f069b4ff06e30ff902b0d5de9846f8f9d Mon Sep 17 00:00:00 2001 From: Will Cornwell Date: Tue, 13 Aug 2024 15:46:16 +1000 Subject: [PATCH 1/3] New function and bumping to version 1.1.0 (#240) * Bump version number (1.0.0.9000) [skip ci] * spelling fixes and removing special Mac install instructions (#229) * spelling fixes and removing special Mac install instructions * adding mac back into CI * Cran preparations (#230) * Added example for default_version, updated LICENSE year, added R CMD CHECK results * Comment about Tidy and Mac and HTML validation * Updated CITATION file * Updated version numbers * cleaning up (#231) * Added example for default_version, updated LICENSE year, added R CMD CHECK results * Comment about Tidy and Mac and HTML validation * Updated CITATION file * Updated version numbers * Removed auto package version in citation * Updated CRAN comments * Fixed typo in CITATION * Resubmitted --------- Co-authored-by: Fonti Kar * fixing badges * Tweaks (#234) * fix example * fix vignette paths * testing for issue #235 * still working on #235 * one more try to find the edge case * another edge case? * reformat code in release file * another edge case * reverting previous commit to documentation * adding check on resources to all functions that need resources * bumping version number and updating readme * missed two checking spots * 238 genus family lookup (#239) * dealing with cran and CI issues (#236) * Bump version number (1.0.0.9000) [skip ci] * spelling fixes and removing special Mac install instructions (#229) * spelling fixes and removing special Mac install instructions * adding mac back into CI * Cran preparations (#230) * Added example for default_version, updated LICENSE year, added R CMD CHECK results * Comment about Tidy and Mac and HTML validation * Updated CITATION file * Updated version numbers * cleaning up (#231) * Added example for default_version, updated LICENSE year, added R CMD CHECK results * Comment about Tidy and Mac and HTML validation * Updated CITATION file * Updated version numbers * Removed auto package version in citation * Updated CRAN comments * Fixed typo in CITATION * Resubmitted --------- Co-authored-by: Fonti Kar * fixing badges * Tweaks (#234) * fix example * fix vignette paths * testing for issue #235 * still working on #235 * one more try to find the edge case * another edge case? * reformat code in release file * another edge case * reverting previous commit to documentation * adding check on resources to all functions that need resources * bumping version number and updating readme * missed two checking spots --------- Co-authored-by: Daniel Falster Co-authored-by: Fonti Kar Co-authored-by: Dave Slager * Update new * fixing bug in hidden function and re-naming a bit * adding new genus in family function * testing? * namespaces * testing testing * forgot how namespaces work * so many details *sigh* --------- Co-authored-by: Daniel Falster Co-authored-by: Fonti Kar Co-authored-by: Dave Slager * bumping version number and updating news * update readme * no empty lines in description --------- Co-authored-by: Daniel Falster Co-authored-by: Fonti Kar Co-authored-by: Dave Slager --- DESCRIPTION | 2 +- NAMESPACE | 1 + NEWS.md | 7 ++- R/state_diversity_counts.R | 52 +++++++++++++++++----- README.Rmd | 28 ++++++++++-- README.md | 31 +++++++++++-- cran-comments.md | 2 + man/get_apc_genus_family_lookup.Rd | 30 +++++++++++++ tests/testthat/benchmarks/family_check.csv | 5 +++ tests/testthat/test-state_diversity.R | 19 ++++++++ 10 files changed, 157 insertions(+), 20 deletions(-) create mode 100644 man/get_apc_genus_family_lookup.Rd create mode 100644 tests/testthat/benchmarks/family_check.csv diff --git a/DESCRIPTION b/DESCRIPTION index cfe461a0..58447698 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: APCalign Title: Resolving Plant Taxon Names Using the Australian Plant Census -Version: 1.0.2 +Version: 1.1.0 Authors@R: c( person(given = "Daniel", family = "Falster", role = c("aut", "cre", "cph"), email = "daniel.falster@unsw.edu.au", comment = c(ORCID = "0000-0002-9814-092X")), person(given = "Elizabeth", family = "Wenk", role = c("aut", "ctb"), email = "e.wenk@unsw.edu.au", comment = c(ORCID = "0000-0001-5640-5910")), diff --git a/NAMESPACE b/NAMESPACE index 78a24c4f..38f686fc 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -4,6 +4,7 @@ export(align_taxa) export(create_species_state_origin_matrix) export(create_taxonomic_update_lookup) export(default_version) +export(get_apc_genus_family_lookup) export(load_taxonomic_resources) export(native_anywhere_in_australia) export(standardise_names) diff --git a/NEWS.md b/NEWS.md index 4abf51d8..5eef954d 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,9 @@ -# APCalign 1.0.2 -Minor update to fix +# APCalign 1.1.0 + +Minor updates and adding one function: + +- Create a genus->family lookup from the specified APC release - Deal with the vignette issues that emerged on CRAN - Improve "graceful failing", based on issues that have come up on github CI diff --git a/R/state_diversity_counts.R b/R/state_diversity_counts.R index 703dfd14..42cb1396 100644 --- a/R/state_diversity_counts.R +++ b/R/state_diversity_counts.R @@ -1,8 +1,8 @@ #' @title State- and territory-level diversity -#' +#' #' @description -#' For Australian states and territories, use geographic distribution data from -#' the APC to calculate state-level diversity for native, introduced, +#' For Australian states and territories, use geographic distribution data from +#' the APC to calculate state-level diversity for native, introduced, #' and more complicated species origins #' #' @family diversity methods @@ -26,6 +26,7 @@ #' #' @examples #' \donttest{state_diversity_counts(state = "NSW")} + state_diversity_counts <- function(state, resources = load_taxonomic_resources()) { @@ -77,14 +78,45 @@ state_diversity_counts <- function(state, #' @noRd -get_apc_genus_family_lookup <- - function(resources = load_taxonomic_resources()) { - apc_s <- dplyr::filter(resources$APC, - taxon_rank == "species") - dplyr::tibble(genus = word(apc_s$scientific_name, 1, 1), - family = apc_s$family) %>% +create_apc_genus_family_lookup <- + function(resources) { + apc_s <- dplyr::filter(resources$APC, taxon_rank == "species") + dplyr::tibble(genus = word(apc_s$accepted_name_usage, 1, 1), + family = apc_s$family) |> dplyr::distinct() -> lu return(lu) } - +#' @title Lookup Family by Genus from APC +#' +#' @description +#' Retrieve the family name for a given genus using taxonomic data from the +#' Australian Plant Census (APC). +#' +#' @param genus A character vector of genus names for which to retrieve the +#' corresponding family names. +#' @param resources The taxonomic resources required to make the lookup. +#' Loading this can be slow, so call \code{\link{load_taxonomic_resources}} +#' separately to speed up this function and pass the resources in. +#' +#' @return A data frame with two columns: "genus", indicating the genus name, +#' and "family", indicating the corresponding family name from the APC. +#' +#' @seealso \code{\link{load_taxonomic_resources}} +#' +#' @export +#' +#' @examples +#' \donttest{get_apc_genus_family_lookup(genus = c("Acacia", "Eucalyptus"))} +get_apc_genus_family_lookup <- + function(genus, resources = load_taxonomic_resources()) { + if (is.null(resources)) { + message("Not finding taxonomic resources; check internet connection?") + return(NULL) + } + fam_lu <- create_apc_genus_family_lookup(resources = resources) + lu <- dplyr::tibble(genus = genus) %>% + dplyr::left_join(fam_lu, by = "genus") + if (any(is.na(lu$family))) warning("some non-matches with the APC accepted genus list, check the formatting of your genus vector.") + return(lu) + } diff --git a/README.Rmd b/README.Rmd index 92272397..baa55020 100644 --- a/README.Rmd +++ b/README.Rmd @@ -31,15 +31,19 @@ the established status (native/introduced) of plant taxa across different states ## Installation -```{r install, eval= FALSE} +From CRAN: - install.packages("APCalign") - # OR for the github version +```{r install, eval= FALSE} + install.packages("APCalign") +``` + + OR for the github version: + +```{r install2, eval= FALSE} install.packages("remotes") remotes::install_github("traitecoevo/APCalign") - ``` ## A quick demo @@ -83,6 +87,22 @@ Checking for a list of species to see if they are classified as Australian nativ native_anywhere_in_australia(c("Eucalyptus globulus","Pinus radiata"), resources = tax_resources) ``` + +Getting a family lookup table for genera from the specified taxonomy: + +```{r, message=FALSE} + +get_apc_genus_family_lookup(c("Eucalyptus", + "Pinus", + "Actinotus", + "Banksia", + "Acacia", + "Triodia"), + resources = tax_resources) + +``` + + ## Shiny application We also developed a shiny application for non-R users to update and align their taxonomic names. You can find the application here: https://unsw.shinyapps.io/APCalign-app diff --git a/README.md b/README.md index 361f6274..9d8aef27 100644 --- a/README.md +++ b/README.md @@ -23,15 +23,18 @@ of established status (native/introduced). ## Installation -``` r +From CRAN: +``` r install.packages("APCalign") +``` - # OR for the github version +OR for the github version: + +``` r install.packages("remotes") remotes::install_github("traitecoevo/APCalign") - ``` ## A quick demo @@ -106,6 +109,28 @@ native_anywhere_in_australia(c("Eucalyptus globulus","Pinus radiata"), resources #> 2 Pinus radiata introduced ``` +Getting a family lookup table for genera from the specified taxonomy: + +``` r + +get_apc_genus_family_lookup(c("Eucalyptus", + "Pinus", + "Actinotus", + "Banksia", + "Acacia", + "Triodia"), + resources = tax_resources) +#> # A tibble: 6 × 2 +#> genus family +#> +#> 1 Eucalyptus Myrtaceae +#> 2 Pinus Pinaceae +#> 3 Actinotus Apiaceae +#> 4 Banksia Proteaceae +#> 5 Acacia Fabaceae +#> 6 Triodia Poaceae +``` + ## Shiny application We also developed a shiny application for non-R users to update and diff --git a/cran-comments.md b/cran-comments.md index 5115f504..59a78f43 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -6,4 +6,6 @@ * This is a resubmission * More gracefully handling edge cases involving parts of the internet being down * Better handling an error in the vignette specific to certain MacOS versions +* Adding one user function for genus->family lookup + diff --git a/man/get_apc_genus_family_lookup.Rd b/man/get_apc_genus_family_lookup.Rd new file mode 100644 index 00000000..98f46f2e --- /dev/null +++ b/man/get_apc_genus_family_lookup.Rd @@ -0,0 +1,30 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/state_diversity_counts.R +\name{get_apc_genus_family_lookup} +\alias{get_apc_genus_family_lookup} +\title{Lookup Family by Genus from APC} +\usage{ +get_apc_genus_family_lookup(genus, resources = load_taxonomic_resources()) +} +\arguments{ +\item{genus}{A character vector of genus names for which to retrieve the +corresponding family names.} + +\item{resources}{The taxonomic resources required to make the lookup. +Loading this can be slow, so call \code{\link{load_taxonomic_resources}} +separately to speed up this function and pass the resources in.} +} +\value{ +A data frame with two columns: "genus", indicating the genus name, +and "family", indicating the corresponding family name from the APC. +} +\description{ +Retrieve the family name for a given genus using taxonomic data from the +Australian Plant Census (APC). +} +\examples{ + \donttest{get_apc_genus_family_lookup(genus = c("Acacia", "Eucalyptus"))} +} +\seealso{ +\code{\link{load_taxonomic_resources}} +} diff --git a/tests/testthat/benchmarks/family_check.csv b/tests/testthat/benchmarks/family_check.csv new file mode 100644 index 00000000..72a5e300 --- /dev/null +++ b/tests/testthat/benchmarks/family_check.csv @@ -0,0 +1,5 @@ +genus,family +Eucalyptus,Myrtaceae +Pinus,Pinaceae +Brassica,Brassicaceae +not a species,NA diff --git a/tests/testthat/test-state_diversity.R b/tests/testthat/test-state_diversity.R index b207f831..c22afee8 100644 --- a/tests/testthat/test-state_diversity.R +++ b/tests/testthat/test-state_diversity.R @@ -33,3 +33,22 @@ test_that("native_anywhere_in_australia() works", { expect_equal(native_check, previous_check) expect_warning(native_anywhere_in_australia(species = "NOTASPECIES", resources = resources)) }) + + +test_that("get_apc_genus_family_lookup() works", { + expect_warning(family_check <- + get_apc_genus_family_lookup( + c( + "Eucalyptus", + "Pinus", + "Brassica", + "not a species" + ), + resources = resources + )) + # readr::write_csv(family_check,"tests/testthat/benchmarks/family_check.csv") + previous_check <- readr::read_csv("benchmarks/family_check.csv", show_col_types = FALSE) + expect_equal(family_check, previous_check) +}) + + From 391a058af2cffc21a5f02f2e39cad7502374b8b0 Mon Sep 17 00:00:00 2001 From: Daniel Falster Date: Mon, 19 Aug 2024 09:47:47 +1000 Subject: [PATCH 2/3] Update news --- NEWS.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/NEWS.md b/NEWS.md index 5eef954d..32476ca7 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,10 +1,12 @@ # APCalign 1.1.0 -Minor updates and adding one function: - - Create a genus->family lookup from the specified APC release +# APCalign 1.0.2 + +Minor update to fix + - Deal with the vignette issues that emerged on CRAN - Improve "graceful failing", based on issues that have come up on github CI - minor formatting From fa592d7fca9317b3c06bf4a49a8acd89e62a6fcc Mon Sep 17 00:00:00 2001 From: Will Cornwell Date: Mon, 26 Aug 2024 17:21:18 +1000 Subject: [PATCH 3/3] fixing pkg down --- _pkgdown.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/_pkgdown.yml b/_pkgdown.yml index 8028a94d..cc791bc6 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -30,6 +30,7 @@ reference: - create_taxonomic_update_lookup - align_taxa - update_taxonomy + - get_apc_genus_family_lookup - subtitle: Standardise and simplify plant taxon names - contents: - standardise_names