Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New function and bumping to version 1.1.0 #240

Merged
merged 22 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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 = "[email protected]", comment = c(ORCID = "0000-0002-9814-092X")),
person(given = "Elizabeth", family = "Wenk", role = c("aut", "ctb"), email = "[email protected]", comment = c(ORCID = "0000-0001-5640-5910")),
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 5 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
52 changes: 42 additions & 10 deletions R/state_diversity_counts.R
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -26,6 +26,7 @@
#'
#' @examples
#' \donttest{state_diversity_counts(state = "NSW")}

state_diversity_counts <- function(state,
resources = load_taxonomic_resources()) {

Expand Down Expand Up @@ -77,14 +78,45 @@


#' @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)

Check warning on line 115 in R/state_diversity_counts.R

View check run for this annotation

Codecov / codecov/patch

R/state_diversity_counts.R#L114-L115

Added lines #L114 - L115 were not covered by tests
}
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)
}
28 changes: 24 additions & 4 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
31 changes: 28 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
#> <chr> <chr>
#> 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
Expand Down
2 changes: 2 additions & 0 deletions cran-comments.md
Original file line number Diff line number Diff line change
Expand Up @@ -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


30 changes: 30 additions & 0 deletions man/get_apc_genus_family_lookup.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions tests/testthat/benchmarks/family_check.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
genus,family
Eucalyptus,Myrtaceae
Pinus,Pinaceae
Brassica,Brassicaceae
not a species,NA
19 changes: 19 additions & 0 deletions tests/testthat/test-state_diversity.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})


Loading