Skip to content

Commit

Permalink
Allow single quotes in get_gbifid
Browse files Browse the repository at this point in the history
relates to #928
  • Loading branch information
zachary-foster committed Feb 3, 2025
1 parent 81a35ee commit c4a24f9
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Description: Interacts with a suite of web 'APIs' for taxonomic tasks,
species names, getting taxonomic hierarchies, fetching downstream and
upstream taxonomic names, getting taxonomic synonyms, converting
scientific to common names and vice versa, and more.
Version: 0.9.102
Version: 0.10.0
License: MIT + file LICENSE
URL: https://docs.ropensci.org/taxize/ (website),
https://github.com/ropensci/taxize (devel),
Expand Down
5 changes: 5 additions & 0 deletions R/class2tree.R
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,12 @@
#' }
#'
class2tree <- function(input, varstep = TRUE, check = TRUE, remove_shared = FALSE, ...) {

if (any(is.na(input))) {
message('Removed species without classification')
input <- input[!is.na(input)]
}


# Check that there is more than 2 taxon
if (length(input) < 3)
Expand All @@ -78,6 +80,9 @@ class2tree <- function(input, varstep = TRUE, check = TRUE, remove_shared = FALS
if (length(unique(names(input))) < length(names(input)))
stop("Input list of classifications contains duplicates")

# Convert tibbles to data.frames
input <- lapply(input, as.data.frame)

# Get rank and ID list
message('Get all ranks and their taxIDs')
rankList <- dt2df(lapply(input, get_rank), idcol = FALSE)
Expand Down
3 changes: 2 additions & 1 deletion R/gbif_helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ gbif_name_backbone <- function(name, rank = NULL, kingdom = NULL, phylum = NULL,
class = NULL, order = NULL, family = NULL, genus = NULL, strict = FALSE,
start = NULL, limit = 500, ...) {


url = 'https://api.gbif.org/v1/species/match'
args <- tc(list(name = name, rank = rank, kingdom = kingdom,
phylum = phylum, class = class, order = order, family = family,
Expand All @@ -13,7 +14,7 @@ gbif_name_backbone <- function(name, rank = NULL, kingdom = NULL, phylum = NULL,
temp$raise_for_status()
tt <- jsonlite::fromJSON(temp$parse("UTF-8"), FALSE)

if (all(names(tt) %in% c('confidence', 'synonym', 'matchType'))) {
if (all(names(tt) %in% c('confidence', 'synonym', 'matchType', "note"))) {
data.frame(NULL)
} else {
dd <- data.table::setDF(
Expand Down
4 changes: 4 additions & 0 deletions R/get_gbifid.R
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ get_gbifid <- function(sci, ask = TRUE, messages = TRUE, rows = NA,
assert(rank, "character")
assert(method, "character")
assert_rows(rows)

# Escape problematic characters
sci <- gsub(sci, pattern = "[^\\]?'", replacement = "\\\\'")

if (!is.null(sciname)) {
lifecycle::deprecate_warn(when = "v0.9.97", what = "get_gbifid(sciname)", with = "get_gbifid(sci)")
sci <- sciname
Expand Down

0 comments on commit c4a24f9

Please sign in to comment.