Skip to content

Commit

Permalink
New function and bumping to version 1.1.0 (#240)
Browse files Browse the repository at this point in the history
* 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 <f.kar@unsw.edu.au>

* 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 <f.kar@unsw.edu.au>

* 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 <daniel.falster@unsw.edu.au>
Co-authored-by: Fonti Kar <f.kar@unsw.edu.au>
Co-authored-by: Dave Slager <slager@users.noreply.github.com>

* 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 <daniel.falster@unsw.edu.au>
Co-authored-by: Fonti Kar <f.kar@unsw.edu.au>
Co-authored-by: Dave Slager <slager@users.noreply.github.com>

* bumping version number and updating news

* update readme

* no empty lines in description

---------

Co-authored-by: Daniel Falster <daniel.falster@unsw.edu.au>
Co-authored-by: Fonti Kar <f.kar@unsw.edu.au>
Co-authored-by: Dave Slager <slager@users.noreply.github.com>
  • Loading branch information
4 people authored Aug 13, 2024
1 parent bd24903 commit 005e3d3
Show file tree
Hide file tree
Showing 10 changed files with 157 additions and 20 deletions.
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 = "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")),
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 @@ 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)
}
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)
})


0 comments on commit 005e3d3

Please sign in to comment.