Skip to content

Commit

Permalink
Merge pull request #12 from jrdnbradford/tax-update-action
Browse files Browse the repository at this point in the history
Tax update action
  • Loading branch information
jrdnbradford authored Jul 13, 2024
2 parents 84dd1a6 + 5e0b663 commit b940ba8
Show file tree
Hide file tree
Showing 16 changed files with 29,186 additions and 78 deletions.
Original file line number Diff line number Diff line change
@@ -1,29 +1,24 @@
name: taxonomy-check
name: taxonomy-version-check

on:
schedule:
- cron: '0 13 * * 1' # Weekly on Mondays at 9AM EST
- cron: '0 0 * 8-11 1' # Midnight on Mondays from August through November

env:
ISSUE_TITLE: 'eBird taxonomy different than expected'
ISSUE_TITLE: 'eBird taxonomy has updated'
ISSUE_BODY: |
This issue has been opened by the GitHub Action workflow `taxonomy-check`.
This issue has been opened by the GitHub Action workflow `taxonomy-version-check`.
The `tax` dataset is different than data retrieved using `rebird::ebirdtaxonomy()`. Potential causes of this could include:
* an update to the eBird taxonomy
* issues with eBird's API
* different versions of R/packages resulting in data being loaded, retrieved, compared, and/or saved differently
Check if there has been an update to eBird's taxonomy data. If not, investigate the other potential causes.
There is an update to the eBird taxonomy. The `rebird::tax` dataset and documentation needs to be updated.
jobs:
taxonomy-check-job:
taxonomy-version-check-job:
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
R_KEEP_PKG_SOURCE: yes
outputs:
result: ${{ steps.check-taxonomy.outputs.result }}
check-failed: ${{ steps.check-taxonomy-version.outputs.failed }}
steps:
- name: checkout-step
uses: actions/checkout@v4
Expand All @@ -39,13 +34,14 @@ jobs:
with:
extra-packages: local::.

- name: check-taxonomy-step
id: check-taxonomy
run: Rscript data-raw/tax_check.R
- name: check-taxonomy-version-step
id: check-taxonomy-version
run: |
Rscript -e "testthat::test_file('tests/testthat/test-data.R', load_package = 'source', stop_on_failure = TRUE)" && echo "failed=false" >> "$GITHUB_OUTPUT" || echo "failed=true" >> "$GITHUB_OUTPUT"
check-and-create-issue-job:
needs: taxonomy-check-job
if: needs.taxonomy-check-job.outputs.result == 'TRUE'
needs: taxonomy-version-check-job
if: needs.taxonomy-version-check-job.outputs.check-failed == 'true'
runs-on: ubuntu-latest
steps:
- name: check-issue-step
Expand Down
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Suggests:
covr,
vcr (>= 0.6.0),
withr
RoxygenNote: 7.3.1
RoxygenNote: 7.3.2
X-schema.org-applicationCategory: Data Access
X-schema.org-keywords: birds, birding, ebird, database, data, biology, observations, sightings, ornithology
X-schema.org-isPartOf: https://ropensci.org
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export(ebirdregioninfo)
export(ebirdregionspecies)
export(ebirdsubregionlist)
export(ebirdtaxonomy)
export(ebirdtaxonomyversion)
export(getlatlng)
export(nearestobs)
export(species_code)
Expand Down
8 changes: 3 additions & 5 deletions R/ebirdtaxonomy.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,12 @@ ebirdtaxonomy <- function(cat=NULL, locale=NULL, species = NULL, key = NULL, ...
species <- if(!is.null(species)) species <- paste0(species, collapse = ",")
args <- list(fmt='json', cat=cat, locale=locale, species=species)

# Allow not using a key for just this function, it's the only endpoint
# that allows it
# Allow not using a key for this function
if (is.null(key) && !nzchar(Sys.getenv("EBIRD_KEY"))) {
key <- ""
}

tax <- ebird_GET(paste0(ebase(), 'ref/taxonomy/ebird'), args, key = key, ...)
tax$comNameCodes <- sort_comma_separated(tax$comNameCodes)
tax$sciNameCodes <- sort_comma_separated(tax$sciNameCodes)
attr(tax, "version") <- ebirdtaxonomyversion(latest_only = TRUE)
tax
}
42 changes: 42 additions & 0 deletions R/ebirdtaxonomyversion.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#' eBird Taxonomy Version
#'
#' Returns a data.frame of available version numbers of
#' the eBird taxonomy or the latest version number of the
#' taxonomy.
#'
#' @param key eBird API key. You can obtain one from https://ebird.org/api/keygen.
#' We strongly recommend storing it in your \code{.Renviron} file as an
#' environment variable called \code{EBIRD_KEY} to avoid having to constantly
#' supply the key, and to avoid accidentally sharing it publicly.
#' @param latest_only Whether to return only the latest version number
#' @param ... Curl options passed on to \code{\link[httr]{GET}}
#'
#' @return If `latest_only = FALSE`, a data.frame containing the collected information:
#' @return "authorityVer": Character of version.
#' @return "latest": Boolean indicating whether `authorityVer`` is the latest taxonomy version
#' @return If `latest_only = TRUE`, a character of the latest `authorityVer`
#'
#' @export
#'
#' @examples \dontrun{
#' ebirdtaxonomyversion()
#' ebirdtaxonomyversion(latest_only = TRUE)
#' }
#' @author Jordan Bradford \email{jrdnbradford@gmail.com}
#' @references \url{http://ebird.org/}
ebirdtaxonomyversion <- function(key = NULL, latest_only = FALSE, ...) {
args <- list(fmt = 'json')

# Allow not using a key for this function
if (is.null(key) && !nzchar(Sys.getenv("EBIRD_KEY"))) {
key <- ""
}

versions <- ebird_GET(paste0(ebase(), 'ref/taxonomy/versions'), args, key = key, ...)
versions$authorityVer <- sub("0+$", "", as.character(versions$authorityVer))

if (latest_only) {
return(subset(versions, latest == TRUE)$authorityVer)
}
versions
}
13 changes: 0 additions & 13 deletions R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,3 @@ ebird_GET <- function(url, args, key = NULL, ...){
}
}
}

sort_comma_separated <- function(x) {
sapply(strsplit(as.character(x), ","), function(x) {
x <- x[x != ""]
if (length(x) == 0) {
return(NA_character_)
} else if (length(x) == 1) {
return(x)
} else {
return(paste(sort(x), collapse = ","))
}
})
}
1 change: 0 additions & 1 deletion README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ knitr::opts_chunk$set(
[![Codecov test coverage](https://codecov.io/gh/ropensci/rebird/branch/master/graph/badge.svg)](https://app.codecov.io/gh/ropensci/rebird?branch=master)
[![rstudio mirror downloads](https://cranlogs.r-pkg.org/badges/rebird)](https://github.com/r-hub/cranlogs.app)
[![cran version](https://www.r-pkg.org/badges/version/rebird)](https://cran.r-project.org/package=rebird/)
[![taxonomy-check](https://github.com/ropensci/rebird/actions/workflows/taxonomy-check.yaml/badge.svg)](https://github.com/ropensci/rebird/actions/workflows/taxonomy-check.yaml)
<!-- badges: end -->

`rebird` is a package to interface with the eBird webservices.
Expand Down
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ coverage](https://codecov.io/gh/ropensci/rebird/branch/master/graph/badge.svg)](
downloads](https://cranlogs.r-pkg.org/badges/rebird)](https://github.com/r-hub/cranlogs.app)
[![cran
version](https://www.r-pkg.org/badges/version/rebird)](https://cran.r-project.org/package=rebird/)
[![taxonomy-check](https://github.com/ropensci/rebird/actions/workflows/taxonomy-check.yaml/badge.svg)](https://github.com/ropensci/rebird/actions/workflows/taxonomy-check.yaml)

<!-- badges: end -->

`rebird` is a package to interface with the eBird webservices.
Expand Down
21 changes: 0 additions & 21 deletions data-raw/tax_check.R

This file was deleted.

Binary file modified data/tax.rda
Binary file not shown.
44 changes: 44 additions & 0 deletions man/ebirdtaxonomyversion.Rd

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

Loading

0 comments on commit b940ba8

Please sign in to comment.