Skip to content

Commit

Permalink
Made use of taxize conditional, as it is now orphaned.
Browse files Browse the repository at this point in the history
  • Loading branch information
hannahlowens committed Sep 4, 2024
1 parent d6ebda8 commit 24149a2
Show file tree
Hide file tree
Showing 36 changed files with 526 additions and 533 deletions.
3 changes: 0 additions & 3 deletions CRAN-SUBMISSION

This file was deleted.

8 changes: 4 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: occCite
Type: Package
Title: Querying and Managing Large Biodiversity Occurrence Datasets
Version: 0.5.7
Version: 0.5.8
Authors@R: c(
person(given = "Hannah L.", family = "Owens", ,"[email protected]", role=c("aut","cre"),
comment = c(ORCID = "0000-0003-0071-1745")),
Expand Down Expand Up @@ -38,7 +38,8 @@ Suggests:
ape,
bit64,
knitr,
httr
httr,
taxize
Imports:
bib2df,
BIEN,
Expand All @@ -47,7 +48,6 @@ Imports:
lubridate,
methods,
rgbif (>= 3.1),
taxize,
stringr,
stats,
leaflet,
Expand All @@ -61,4 +61,4 @@ Imports:
DBI,
waffle
VignetteBuilder: knitr, rmarkdown
RoxygenNote: 7.3.1
RoxygenNote: 7.3.2
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# occCite 0.5.8

* Moved `taxize` package to `Suggests`, as it is now orphaned.
* `studyTaxonList()` allows user to skip taxonomic rectification, which relies on functions from `taxize` package. `studyTaxonList()` automatically skips taxonomic rectification if `taxize` is unavailable.

# occCite 0.5.7

* Fixed warning in `occCitation()` when getting GBIF citations
Expand Down
159 changes: 98 additions & 61 deletions R/taxonRectification.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
#' \code{\link[taxize]{gnr_resolve}}. See the
#' \href{http://gni.globalnames.org/}{Global Names List} for more information.
#'
#' @param skipTaxize If \code{skipTaxize = TRUE}, occCite will skip taxonomic
#' rectification using taxize, which has been orphaned on CRAN. Setting this
#' option to `TRUE` will result in a check for the taxize package before taxonomic
#' rectification is attempted.
#'
#' @return A string with the closest match according to
#' \code{\link[taxize]{gnr_resolve}}, and a list of taxonomic data sources that
#' contain the matching name.
Expand All @@ -22,77 +27,109 @@
#' )
#' @export
#'
taxonRectification <- function(taxName = NULL, datasources = NULL) {

# Checks for source connectivity
tryCatch(
expr = sources <- taxize::gnr_datasources(),
error = function(e) {
message(paste("GNR server unreachable; please try again later. \n"))
}
)
taxonRectification <- function(taxName = NULL, datasources = NULL,
skipTaxize = FALSE) {

if (!exists("sources")) {
return(invisible(NULL))
if (!is.logical(skipTaxize)) {
warning(paste0(
"You have not used a logical operator to\n",
"specify whether occCite should skip taxize-\n",
"based taxonomic rectification."
))
return(NULL)
}

if(!skipTaxize){
if(!requireNamespace("taxize", quietly = TRUE)){
warning(paste0("Package taxize unavailable. Skipping taxonomic rectification."))
skipTaxize <- TRUE
}
}

# Are user-input databases included in data sources for Global Names Resolver?
if (!is.null(datasources)) {
for (db in datasources) {
notInDB <- character()
if (!(db %in% sources$title)) {
notInDB <- append(notInDB, db)
if(skipTaxize){
resolvedNames <- data.frame(taxName, taxName, "Not rectified.")
colnames(resolvedNames) <- c(
"Input Name",
"Best Match",
"Searched Taxonomic Databases w/ Matches"
)
resolvedNames <- as.data.frame(resolvedNames)

return(resolvedNames)


} else{
# Checks for source connectivity
tryCatch(
expr = sources <- taxize::gnr_datasources(),
error = function(e) {
message(paste("GNR server unreachable; please try again later. \n"))
}
)

if (!exists("sources")) {
return(invisible(NULL))
}

# Are user-input databases included in data sources for Global Names Resolver?
if (!is.null(datasources)) {
for (db in datasources) {
notInDB <- character()
if (!(db %in% sources$title)) {
notInDB <- append(notInDB, db)
}
}
if (length(notInDB) != 0) {
warning(paste0(
"Following sources not found in\n",
"Global Names Index source list: ",
paste(notInDB, collapse = ", ")
))
}
# Remove invalid sources from datasources
datasources <- datasources[!datasources %in% notInDB]
}
if (length(notInDB) != 0) {

# Populating vector of data sources if no valid sources are supplied
if (length(datasources) == 0) {
warning(paste0(
"Following sources not found in\n",
"Global Names Index source list: ",
paste(notInDB, collapse = ", ")
"No valid taxonomic data sources supplied.\n",
"Populating default list from all available sources."
))
datasources <- sources$title
}
# Remove invalid sources from datasources
datasources <- datasources[!datasources %in% notInDB]
}

# Populating vector of data sources if no valid sources are supplied
if (length(datasources) == 0) {
warning(paste0(
"No valid taxonomic data sources supplied.\n",
"Populating default list from all available sources."
))
datasources <- sources$title
}

# Resolving the user-input taxonomic names
sourceIDs <- sources$id[sources$title %in% datasources]
# Protects from error when gnr_resolve gets complete list of data sources
if (nrow(sources) == length(sourceIDs)) {
sourceIDs <- NULL
}
taxonomicDatabaseMatches <- vector("list")
temp <- taxize::gnr_resolve(sci = taxName, data_source_ids = sourceIDs)
if (nrow(temp) == 0) {
bestMatch <- "No match"
taxonomicDatabaseMatches <- "No match"
warning(paste(taxName,
" is not found in any of the taxonomic data sources specified.",
sep = ""
))
} else {
bestMatch <- temp[order(temp$score), ]$matched_name[1]
matchingSources <- temp$data_source_title[temp$matched_name == bestMatch]
taxonomicDatabaseMatches <- paste(matchingSources, collapse = "; ")
}
# Resolving the user-input taxonomic names
sourceIDs <- sources$id[sources$title %in% datasources]
# Protects from error when gnr_resolve gets complete list of data sources
if (nrow(sources) == length(sourceIDs)) {
sourceIDs <- NULL
}
taxonomicDatabaseMatches <- vector("list")
temp <- taxize::gnr_resolve(sci = taxName, data_source_ids = sourceIDs)
if (nrow(temp) == 0) {
bestMatch <- "No match"
taxonomicDatabaseMatches <- "No match"
warning(paste(taxName,
" is not found in any of the taxonomic data sources specified.",
sep = ""
))
} else {
bestMatch <- temp[order(temp$score), ]$matched_name[1]
matchingSources <- temp$data_source_title[temp$matched_name == bestMatch]
taxonomicDatabaseMatches <- paste(matchingSources, collapse = "; ")
}

# Building the results table
resolvedNames <- data.frame(taxName, bestMatch, taxonomicDatabaseMatches)
colnames(resolvedNames) <- c(
"Input Name",
"Best Match",
"Searched Taxonomic Databases w/ Matches"
)
resolvedNames <- as.data.frame(resolvedNames)
# Building the results table
resolvedNames <- data.frame(taxName, bestMatch, taxonomicDatabaseMatches)
colnames(resolvedNames) <- c(
"Input Name",
"Best Match",
"Searched Taxonomic Databases w/ Matches"
)
resolvedNames <- as.data.frame(resolvedNames)

return(resolvedNames)
return(resolvedNames)
}
}
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,19 @@ citation(package = "occCite")
```

##
## Owens H, Merow C, Maitner B, Kass J, Barve V, Guralnick R (2022).
## Owens H, Merow C, Maitner B, Kass J, Barve V, Guralnick R (2024).
## _occCite: Querying and Managing Large Biodiversity Occurrence
## Datasets_. doi: 10.5281/zenodo.632770 (URL:
## https://doi.org/10.5281/zenodo.632770), R package version 0.5.7,
## https://doi.org/10.5281/zenodo.632770), R package version 0.5.8,
## <URL: https://CRAN.R-project.org/package=occCite>.
##
## A BibTeX entry for LaTeX users is
##
## @Manual{,
## title = {occCite: Querying and Managing Large Biodiversity Occurrence Datasets},
## author = {Hannah Owens and Cory Merow and Brian Maitner and Jamie Kass and Vijay Barve and Robert Guralnick},
## year = {2022},
## note = {R package version 0.5.7},
## year = {2024},
## note = {R package version 0.5.8},
## url = {https://CRAN.R-project.org/package=occCite},
## doi = {10.5281/zenodo.632770},
## }
Expand Down
12 changes: 6 additions & 6 deletions cran-comments.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
## Update
This is a package update. In this version, I have:

* Fixed warning in `occCitation()` when getting GBIF citations
* Updated date formatting using `format()` instead of `as.character()`
* Updated test files to incorporate rgbif 3.8.0 output changes, make more efficient
* In occResults, renamed "Dataset", "DatasetKey", and "DataService" to "datasetName", "datasetKey", "dataService", respectively.
* Made an option for removing package citations.
* Moved `taxize` package to `Suggests`, as it is now orphaned.
* `studyTaxonList()` allows user to skip taxonomic rectification, which relies on functions from `taxize` package. `studyTaxonList()` automatically skips taxonomic rectification if `taxize` is unavailable.

## Test environments
* local OS X 14.5 install, R 4.3.2 (with and without internet connection)
Expand All @@ -14,7 +11,10 @@ This is a package update. In this version, I have:
* macOS-latest (on GitHub Actions), R 4.4.1

## R CMD check results
0 errors | 0 warnings | 0 notes
0 errors | 0 warnings | 1 notes

Note: Suggests orphaned package: ‘taxize’
- Use is conditional on presence of package. If taxize is absent, taxonomic rectification is skipped. This is noted in metadata and does not affect downstream processes.

## Downstream dependencies
I ran tools::check_packages_in_dir() check on downstream dependencies of
Expand Down
16 changes: 8 additions & 8 deletions docs/404.html

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

Loading

0 comments on commit 24149a2

Please sign in to comment.