From f4b0ad18ac28fa42f5e50c483b15d5703ef7c6d6 Mon Sep 17 00:00:00 2001 From: Scott Chamberlain Date: Wed, 20 May 2020 18:01:47 -0700 Subject: [PATCH] #723 standardize param names: done updating search fxns and get_* fxns updated docs of these functions and fixed their tests started a new man file taxize-params with informaiton on standardized parameters --- R/bold_search.R | 34 ++++++------ R/eol_search.R | 16 +++--- R/get_boldid.R | 69 ++++++++++++----------- R/get_eolid.R | 64 ++++++++++++---------- R/get_gbifid.R | 74 +++++++++++++------------ R/get_ids.R | 71 ++++++++++++------------ R/get_iucn.R | 43 ++++++++------- R/get_natservid.R | 55 ++++++++++--------- R/get_nbnid.R | 65 +++++++++++----------- R/get_pow.R | 55 ++++++++++--------- R/get_tolid.R | 58 +++++++++++--------- R/get_tpsid.R | 60 +++++++++++--------- R/get_tsn.R | 57 ++++++++++--------- R/get_uid.R | 85 +++++++++++++++-------------- R/get_wiki.R | 51 +++++++++-------- R/get_wormsid.R | 54 +++++++++--------- R/gni_search.R | 49 +++++++++-------- R/nbn_search.R | 16 +++--- R/pow_search.R | 22 +++++--- R/taxize-params.R | 20 +++++++ R/tp_search.R | 57 +++++++++++-------- R/zzz.R | 22 ++++++++ man/bold_search.Rd | 25 +++++---- man/eol_search.Rd | 13 +++-- man/get_boldid.Rd | 24 ++++---- man/get_eolid.Rd | 15 +++-- man/get_gbifid.Rd | 29 ++++++---- man/get_ids.Rd | 38 ++++++++----- man/get_iucn.Rd | 13 +++-- man/get_natservid.Rd | 10 +++- man/get_nbnid.Rd | 24 ++++---- man/get_pow.Rd | 16 ++++-- man/get_tolid.Rd | 14 +++-- man/get_tpsid.Rd | 15 +++-- man/get_tsn.Rd | 12 ++-- man/get_uid.Rd | 35 ++++++------ man/get_wiki.Rd | 16 ++++-- man/get_wormsid.Rd | 12 ++-- man/gni_search.Rd | 47 ++++++++-------- man/nbn_search.Rd | 13 +++-- man/pow_search.Rd | 16 +++--- man/taxize-params.Rd | 26 +++++++++ man/tp_search.Rd | 38 +++++++------ tests/testthat/test-bold_search.R | 10 ++-- tests/testthat/test-eol_search.R | 2 +- tests/testthat/test-get_boldid.R | 6 +- tests/testthat/test-get_eolid.R | 6 +- tests/testthat/test-get_gbifid.R | 8 +-- tests/testthat/test-get_ids.R | 6 +- tests/testthat/test-get_natservid.R | 2 +- tests/testthat/test-get_pow.R | 2 +- tests/testthat/test-get_tolid.R | 2 +- tests/testthat/test-get_tpsid.R | 8 +-- tests/testthat/test-get_tsn.R | 6 +- tests/testthat/test-get_uid.R | 26 ++++----- tests/testthat/test-get_wormsid.R | 2 +- tests/testthat/test-gni_search.R | 2 +- tests/testthat/test-pow_search.R | 6 +- tests/testthat/test-tp_search.R | 4 +- 59 files changed, 934 insertions(+), 712 deletions(-) create mode 100644 R/taxize-params.R create mode 100644 man/taxize-params.Rd diff --git a/R/bold_search.R b/R/bold_search.R index e9bf2484..ed871f2f 100644 --- a/R/bold_search.R +++ b/R/bold_search.R @@ -1,7 +1,7 @@ #' Search Barcode of Life for taxonomic IDs #' #' @export -#' @param name (character) One or more scientific names. +#' @param sci (character) One or more scientific names. #' @param id (integer) One or more BOLD taxonomic identifiers. #' @param fuzzy (logical) Whether to use fuzzy search or not (default: `FALSE`). #' Only used if `name` passed. @@ -13,9 +13,10 @@ #' passed. #' @param response (logical) Note that response is the object that returns from the #' curl call, useful for debugging, and getting detailed info on the API call. +#' @param name Deprecated, see `sci` #' @param ... named curl options passed on to [crul::verb-GET] -#' @details You must provide one of name or id to this function. The other -#' parameters are optional. Note that when passing in `name`, `fuzzy` can be used +#' @details You must provide one of `sci` or `id` to this function. The other +#' parameters are optional. Note that when passing in `sci`, `fuzzy` can be used #' as well, while if `id` is passed, then `fuzzy` is ignored, and `dataTypes` #' `includeTree` can be used. #' @@ -41,18 +42,18 @@ #' @return A list of data.frame's. #' @examples \dontrun{ #' # A basic example -#' bold_search(name="Apis") -#' bold_search(name="Agapostemon") -#' bold_search(name="Poa") +#' bold_search(sci="Apis") +#' bold_search(sci="Agapostemon") +#' bold_search(sci="Poa") #' #' # Fuzzy search -#' head(bold_search(name="Po", fuzzy=TRUE)) -#' head(bold_search(name="Aga", fuzzy=TRUE)) +#' head(bold_search(sci="Po", fuzzy=TRUE)) +#' head(bold_search(sci="Aga", fuzzy=TRUE)) #' #' # Many names -#' bold_search(name=c("Apis","Puma concolor")) +#' bold_search(sci=c("Apis","Puma concolor")) #' nms <- names_list('species') -#' bold_search(name=nms) +#' bold_search(sci=nms) #' #' # Searching by ID - dataTypes can be used, and includeTree can be used #' bold_search(id=88899) @@ -61,14 +62,15 @@ #' bold_search(id=88899, dataTypes="basic") #' bold_search(id=88899, includeTree=TRUE) #' } +bold_search <- function(sci = NULL, id = NULL, fuzzy = FALSE, + dataTypes = 'basic', includeTree=FALSE, response=FALSE, name = NULL, ...) { -bold_search <- function(name = NULL, id = NULL, fuzzy = FALSE, - dataTypes = 'basic', includeTree=FALSE, response=FALSE, ...) { - - stopifnot(!is.null(name) | !is.null(id)) - type <- if (is.null(name)) "id" else "name" + pchk(name, "sci") + if (!is.null(name)) sci <- name + stopifnot(!is.null(sci) | !is.null(id)) + type <- if (is.null(sci)) "id" else "sci" tmp <- switch(type, - name = bold_tax_name(name = name, fuzzy = fuzzy, response = response, ...), + sci = bold_tax_name(name = sci, fuzzy = fuzzy, response = response, ...), id = bold_tax_id(id = id, dataTypes = dataTypes, includeTree = includeTree, response = response, ...) ) diff --git a/R/eol_search.R b/R/eol_search.R index 18149e9b..3488b2b4 100644 --- a/R/eol_search.R +++ b/R/eol_search.R @@ -1,7 +1,7 @@ #' Search for terms in EOL database. #' #' @export -#' @param terms search terms (character) +#' @param sci (character) scientific name #' @param page A maximum of 30 results are returned per page. This parameter #' allows you to fetch more pages of results if there are more than #' 30 matches (Default 1) @@ -15,6 +15,7 @@ #' and that matching page will be used as the taxonomic group against which #' to filter search results #' @param cache_ttl The number of seconds you wish to have the response cached. +#' @param terms Deprecated, see `sci` #' @param ... Curl options passed on to [crul::HttpClient] #' @details It's possible to return JSON or XML with the EOL API. However, #' this function only returns JSON for now. @@ -30,16 +31,17 @@ #' in case some may find it useful #' #' @examples \dontrun{ -#' eol_search(terms='Homo') -#' eol_search(terms='Salix', verbose = TRUE) -#' eol_search(terms='Ursus americanus') +#' eol_search(sci='Homo') +#' eol_search(sci='Salix', verbose = TRUE) +#' eol_search(sci='Ursus americanus') #' eol_search('Pinus contorta') #' } -eol_search <- function(terms, page=1, exact=NULL, filter_tid=NULL, - filter_heid=NULL, filter_by_string=NULL, cache_ttl=NULL, ...) { +eol_search <- function(sci, page=1, exact=NULL, filter_tid=NULL, + filter_heid=NULL, filter_by_string=NULL, cache_ttl=NULL, terms = NULL, ...) { - query <- gsub("\\s", "+", terms) + pchk(terms, "sci") + query <- gsub("\\s", "+", sci) args <- tc(list(q = query, page = page, exact = exact, filter_by_taxon_concept_id = filter_tid, filter_by_hierarchy_entry_id = filter_heid, diff --git a/R/get_boldid.R b/R/get_boldid.R index 330eba6b..eb689856 100644 --- a/R/get_boldid.R +++ b/R/get_boldid.R @@ -2,7 +2,7 @@ #' #' @importFrom bold bold_tax_name bold_tax_id #' @export -#' @param searchterm character; A vector of scientific names. Or, +#' @param sci character; A vector of scientific names. Or, #' a `taxon_state` object (see [taxon-state]) #' @param fuzzy (logical) Whether to use fuzzy search or not (default: FALSE). #' @param dataTypes (character) Specifies the datatypes that will be returned. @@ -28,6 +28,7 @@ #' data itself for options. Optional. See `Filtering` below. #' @param check logical; Check if ID matches any existing on the DB, only used in #' [as.boldid()] +#' @param searchterm Deprecated, see `sci` #' @template getreturn #' #' @section Filtering: @@ -41,20 +42,20 @@ #' @seealso [classification()] #' #' @examples \dontrun{ -#' get_boldid(searchterm = "Agapostemon") -#' get_boldid(searchterm = "Chironomus riparius") +#' get_boldid(sci = "Agapostemon") +#' get_boldid(sci = "Chironomus riparius") #' get_boldid(c("Chironomus riparius","Quercus douglasii")) #' splist <- names_list('species') #' get_boldid(splist, messages=FALSE) #' #' # Fuzzy searching -#' get_boldid(searchterm="Osmi", fuzzy=TRUE) +#' get_boldid(sci="Osmi", fuzzy=TRUE) #' #' # Get back a subset -#' get_boldid(searchterm="Osmi", fuzzy=TRUE, rows = 1) -#' get_boldid(searchterm="Osmi", fuzzy=TRUE, rows = 1:10) -#' get_boldid(searchterm=c("Osmi","Aga"), fuzzy=TRUE, rows = 1) -#' get_boldid(searchterm=c("Osmi","Aga"), fuzzy=TRUE, rows = 1:3) +#' get_boldid(sci="Osmi", fuzzy=TRUE, rows = 1) +#' get_boldid(sci="Osmi", fuzzy=TRUE, rows = 1:10) +#' get_boldid(sci=c("Osmi","Aga"), fuzzy=TRUE, rows = 1) +#' get_boldid(sci=c("Osmi","Aga"), fuzzy=TRUE, rows = 1:3) #' #' # found #' get_boldid('Epicordulia princeps') @@ -107,12 +108,12 @@ #' get_boldid_(c("Osmi","Aga"), fuzzy=TRUE, rows = 1:3) #' } -get_boldid <- function(searchterm, fuzzy = FALSE, dataTypes = 'basic', +get_boldid <- function(sci, fuzzy = FALSE, dataTypes = 'basic', includeTree = FALSE, ask = TRUE, messages = TRUE, rows = NA, rank = NULL, division = NULL, - parent = NULL, ...) { + parent = NULL, searchterm = NULL, ...) { - assert(searchterm, c("character", "taxon_state")) + assert(sci, c("character", "taxon_state")) assert(ask, "logical") assert(messages, "logical") assert(fuzzy, "logical") @@ -122,15 +123,16 @@ get_boldid <- function(searchterm, fuzzy = FALSE, dataTypes = 'basic', assert(division, "character") assert(parent, "character") assert_rows(rows) + pchk(searchterm, "sci") - if (inherits(searchterm, "character")) { - tstate <- taxon_state$new(class = "boldid", names = searchterm) - items <- searchterm + if (inherits(sci, "character")) { + tstate <- taxon_state$new(class = "boldid", names = sci) + items <- sci } else { - assert_state(searchterm, "boldid") - tstate <- searchterm - searchterm <- tstate$taxa_remaining() - items <- c(searchterm, tstate$taxa_completed()) + assert_state(sci, "boldid") + tstate <- sci + sci <- tstate$taxa_remaining() + items <- c(sci, tstate$taxa_completed()) } prog <- progressor$new(items = items, suppress = !messages) @@ -138,10 +140,10 @@ get_boldid <- function(searchterm, fuzzy = FALSE, dataTypes = 'basic', for (i in seq_along(done)) prog$completed(names(done)[i], done[[i]]$att) prog$prog_start() - for (i in seq_along(searchterm)) { + for (i in seq_along(sci)) { direct <- FALSE - mssg(messages, "\nRetrieving data for taxon '", searchterm[i], "'\n") - bold_df <- bold_search(name = searchterm[i], fuzzy = fuzzy, + mssg(messages, "\nRetrieving data for taxon '", sci[i], "'\n") + bold_df <- bold_search(sci = sci[i], fuzzy = fuzzy, dataTypes = dataTypes, includeTree = includeTree, ...) mm <- NROW(bold_df) > 1 @@ -182,7 +184,7 @@ get_boldid <- function(searchterm, fuzzy = FALSE, dataTypes = 'basic', # check for direct match if (nrow(bold_df) > 1) { names(bold_df)[grep('taxon', names(bold_df))] <- "target" - di_rect <- match(tolower(bold_df$target), tolower(searchterm[i])) + di_rect <- match(tolower(bold_df$target), tolower(sci[i])) if (length(di_rect) == 1) { if (!all(is.na(di_rect))) { boldid <- bold_df$taxid[!is.na(di_rect)] @@ -237,7 +239,7 @@ get_boldid <- function(searchterm, fuzzy = FALSE, dataTypes = 'basic', # prompt message("\n\n") print(bold_df) - message("\nMore than one TSN found for taxon '", searchterm[i], "'!\n + message("\nMore than one TSN found for taxon '", sci[i], "'!\n Enter rownumber of taxon (other inputs will return 'NA'):\n") # prompt take <- scan(n = 1, quiet = TRUE, what = 'raw') @@ -259,7 +261,7 @@ get_boldid <- function(searchterm, fuzzy = FALSE, dataTypes = 'basic', if (length(boldid) == 1) { att <- "found" } else { - warning(sprintf(m_more_than_one_found, "boldid", searchterm[i]), + warning(sprintf(m_more_than_one_found, "boldid", sci[i]), call. = FALSE) boldid <- NA_character_ att <- m_na_ask_false @@ -270,9 +272,9 @@ get_boldid <- function(searchterm, fuzzy = FALSE, dataTypes = 'basic', } res <- list(id = as.character(boldid), att = att, multiple = mm, direct = direct) - prog$completed(searchterm[i], att) + prog$completed(sci[i], att) prog$prog(att) - tstate$add(searchterm[i], res) + tstate$add(sci[i], res) } out <- tstate$get() ids <- structure(as.character(unlist(pluck(out, "id"))), class = "boldid", @@ -347,19 +349,20 @@ check_boldid <- function(x){ #' @export #' @rdname get_boldid -get_boldid_ <- function(searchterm, messages = TRUE, fuzzy = FALSE, - dataTypes='basic', includeTree=FALSE, rows = NA, ...) { +get_boldid_ <- function(sci, messages = TRUE, fuzzy = FALSE, + dataTypes='basic', includeTree=FALSE, rows = NA, searchterm = NULL, ...) { - stats::setNames(lapply(searchterm, get_boldid_help, messages = messages, + pchk(searchterm, "sci") + stats::setNames(lapply(sci, get_boldid_help, messages = messages, fuzzy = fuzzy, dataTypes=dataTypes, includeTree=includeTree, - rows = rows, ...), searchterm) + rows = rows, ...), sci) } -get_boldid_help <- function(searchterm, messages, fuzzy, dataTypes, +get_boldid_help <- function(sci, messages, fuzzy, dataTypes, includeTree, rows, ...){ - mssg(messages, "\nRetrieving data for taxon '", searchterm, "'\n") - df <- bold_search(name = searchterm, fuzzy = fuzzy, dataTypes = dataTypes, + mssg(messages, "\nRetrieving data for taxon '", sci, "'\n") + df <- bold_search(name = sci, fuzzy = fuzzy, dataTypes = dataTypes, includeTree = includeTree) if(NROW(df) == 0) NULL else sub_rows(df, rows) } diff --git a/R/get_eolid.R b/R/get_eolid.R index 15fa05fd..4673eece 100644 --- a/R/get_eolid.R +++ b/R/get_eolid.R @@ -6,7 +6,7 @@ #' [eol_pages()] to find the actual taxon IDs. #' #' @export -#' @param sciname character; one or more scientific or common names. Or, +#' @param sci_com character; one or more scientific or common names. Or, #' a `taxon_state` object (see [taxon-state]) #' @param ask logical; should get_eolid be run in interactive mode? #' If TRUE and more than one ID is found for the species, the user is asked for @@ -28,6 +28,7 @@ #' @param x Input to [as.eolid()] #' @param check logical; Check if ID matches any existing on the DB, only #' used in [as.eolid()] +#' @param sciname Deprecated, see `sci_com` #' @template getreturn #' #' @family taxonomic-ids @@ -56,8 +57,8 @@ #' removes the rest. #' #' @examples \dontrun{ -#' get_eolid(sciname='Pinus contorta') -#' get_eolid(sciname='Puma concolor') +#' get_eolid(sci_com='Pinus contorta') +#' get_eolid(sci_com='Puma concolor') #' #' get_eolid(c("Puma concolor", "Pinus contorta")) #' @@ -68,7 +69,7 @@ #' get_eolid('Poa annua', rows=1:2) #' #' # When not found -#' get_eolid(sciname="uaudnadndj") +#' get_eolid(sci_com="uaudnadndj") #' get_eolid(c("Chironomus riparius", "uaudnadndj")) #' #' # filter results to a rank or data source, or both @@ -110,24 +111,25 @@ #' get_eolid_(c("asdfadfasd", "Pinus contorta")) #' } -get_eolid <- function(sciname, ask = TRUE, messages = TRUE, - rows = NA, rank = NULL, data_source = NULL, ...) { +get_eolid <- function(sci_com, ask = TRUE, messages = TRUE, + rows = NA, rank = NULL, data_source = NULL, sciname = NULL, ...) { - assert(sciname, c("character", "taxon_state")) + assert(sci_com, c("character", "taxon_state")) assert(ask, "logical") assert(messages, "logical") assert(rank, "character") assert(data_source, "character") assert_rows(rows) + pchk(sciname, "sci_com") - if (inherits(sciname, "character")) { - tstate <- taxon_state$new(class = "eolid", names = sciname) - items <- sciname + if (inherits(sci_com, "character")) { + tstate <- taxon_state$new(class = "eolid", names = sci_com) + items <- sci_com } else { - assert_state(sciname, "eolid") - tstate <- sciname - sciname <- tstate$taxa_remaining() - items <- c(sciname, tstate$taxa_completed()) + assert_state(sci_com, "eolid") + tstate <- sci_com + sci_com <- tstate$taxa_remaining() + items <- c(sci_com, tstate$taxa_completed()) } prog <- progressor$new(items = items, suppress = !messages) @@ -135,10 +137,10 @@ get_eolid <- function(sciname, ask = TRUE, messages = TRUE, for (i in seq_along(done)) prog$completed(names(done)[i], done[[i]]$att) prog$prog_start() - for (i in seq_along(sciname)) { + for (i in seq_along(sci_com)) { direct <- FALSE - mssg(messages, "\nRetrieving data for taxon '", sciname[i], "'\n") - tmp <- eol_search(terms = sciname[i], ...) + mssg(messages, "\nRetrieving data for taxon '", sci_com[i], "'\n") + tmp <- eol_search(sci = sci_com[i], ...) datasource <- NA_character_ if (all(is.na(tmp))) { mssg(messages, m_not_found_sp_altclass) @@ -147,7 +149,7 @@ get_eolid <- function(sciname, ask = TRUE, messages = TRUE, att <- "not found" mm <- FALSE } else { - pageids <- tmp[grep(tolower(sciname[i]), tolower(tmp$name)), "pageid"] + pageids <- tmp[grep(tolower(sci_com[i]), tolower(tmp$name)), "pageid"] if (length(pageids) == 0) { if (nrow(tmp) > 0) @@ -220,7 +222,7 @@ get_eolid <- function(sciname, ask = TRUE, messages = TRUE, } if (length(id) > 1) { - matchtmp <- df[tolower(df$name) %in% tolower(sciname[i]), ] + matchtmp <- df[tolower(df$name) %in% tolower(sci_com[i]), ] if (NROW(matchtmp) == 1) { id <- matchtmp$eolid direct <- TRUE @@ -236,7 +238,7 @@ get_eolid <- function(sciname, ask = TRUE, messages = TRUE, rownames(df) <- 1:nrow(df) # prompt message("\n\n") - message("\nMore than one eolid found for taxon '", sciname[i], "'!\n + message("\nMore than one eolid found for taxon '", sci_com[i], "'!\n Enter rownumber of taxon (other inputs will return 'NA'):\n") print(df) take <- scan(n = 1, quiet = TRUE, what = "raw") @@ -261,7 +263,7 @@ get_eolid <- function(sciname, ask = TRUE, messages = TRUE, } } else { if (length(id) != 1) { - warning(sprintf(m_more_than_one_found, "eolid", sciname[i]), + warning(sprintf(m_more_than_one_found, "eolid", sci_com[i]), call. = FALSE) id <- NA_character_ page_id <- NA_character_ @@ -271,9 +273,9 @@ get_eolid <- function(sciname, ask = TRUE, messages = TRUE, } res <- list(id = as.character(id), page_id = page_id, source = datasource, att = att, multiple = mm, direct = direct) - prog$completed(sciname[i], att) + prog$completed(sci_com[i], att) prog$prog(att) - tstate$add(sciname[i], res) + tstate$add(sci_com[i], res) } out <- tstate$get() page_ids <- pluck_un(out, "page_id", "") @@ -387,19 +389,21 @@ get_eol_pageid <- function(x) { #' @export #' @rdname get_eolid -get_eolid_ <- function(sciname, messages = TRUE, rows = NA, ...) { - stats::setNames(lapply(sciname, get_eolid_help, messages = messages, - rows = rows, ...), sciname) +get_eolid_ <- function(sci_com, messages = TRUE, rows = NA, sciname = NULL, + ...) { + pchk(sciname, "sci_com") + stats::setNames(lapply(sci_com, get_eolid_help, messages = messages, + rows = rows, ...), sci_com) } -get_eolid_help <- function(sciname, messages, rows, ...) { - mssg(messages, "\nRetrieving data for taxon '", sciname, "'\n") - tmp <- eol_search(terms = sciname, ...) +get_eolid_help <- function(sci_com, messages, rows, ...) { + mssg(messages, "\nRetrieving data for taxon '", sci_com, "'\n") + tmp <- eol_search(terms = sci_com, ...) if (all(is.na(tmp))) { NULL } else { - pageids <- tmp[grep(tolower(sciname), tolower(tmp$name)), "pageid"] + pageids <- tmp[grep(tolower(sci_com), tolower(tmp$name)), "pageid"] if (length(pageids) == 0) { NULL } else { diff --git a/R/get_gbifid.R b/R/get_gbifid.R index 3e61fc4a..8f90036c 100644 --- a/R/get_gbifid.R +++ b/R/get_gbifid.R @@ -1,7 +1,7 @@ #' Get the GBIF backbone taxon ID from taxonomic names. #' #' @export -#' @param sciname (character) one or more scientific names. Or, a `taxon_state` +#' @param sci (character) one or more scientific names. Or, a `taxon_state` #' object (see [taxon-state]) #' @param ask logical; should get_gbifid be run in interactive mode? #' If TRUE and more than one ID is found for the species, the user is asked for @@ -24,6 +24,7 @@ #' @param check logical; Check if ID matches any existing on the DB, only used in #' [as.gbifid()] #' @param ... Ignored +#' @param sciname Deprecated, see `sci` #' @template getreturn #' #' @family taxonomic-ids @@ -51,9 +52,9 @@ #' Filtering narrows down to the set that matches your query, and removes the rest. #' #' @examples \dontrun{ -#' get_gbifid(sciname='Poa annua') -#' get_gbifid(sciname='Pinus contorta') -#' get_gbifid(sciname='Puma concolor') +#' get_gbifid(sci='Poa annua') +#' get_gbifid(sci='Pinus contorta') +#' get_gbifid(sci='Puma concolor') #' #' #lots of queries #' spp <- names_list("species", 10) @@ -66,12 +67,12 @@ #' get_gbifid(c("Poa annua", "Pinus contorta")) #' #' # specify rows to limit choices available -#' get_gbifid(sciname='Pinus') -#' get_gbifid(sciname='Pinus', rows=10) -#' get_gbifid(sciname='Pinus', rows=1:3) +#' get_gbifid(sci='Pinus') +#' get_gbifid(sci='Pinus', rows=10) +#' get_gbifid(sci='Pinus', rows=1:3) #' #' # When not found, NA given -#' get_gbifid(sciname="uaudnadndj") +#' get_gbifid(sci="uaudnadndj") #' get_gbifid(c("Chironomus riparius", "uaudnadndj")) #' #' # Narrow down results to a division or rank, or both @@ -124,12 +125,12 @@ #' invisible(get_gbifid("Quercus douglasii", verbose = TRUE)) #' } -get_gbifid <- function(sciname, ask = TRUE, messages = TRUE, rows = NA, +get_gbifid <- function(sci, ask = TRUE, messages = TRUE, rows = NA, phylum = NULL, class = NULL, order = NULL, - family = NULL, rank = NULL, method = "backbone", - ...) { + family = NULL, rank = NULL, method = "backbone", + sciname = NULL, ...) { - assert(sciname, c("character", "taxon_state")) + assert(sci, c("character", "taxon_state")) assert(ask, "logical") assert(messages, "logical") assert(phylum, "character") @@ -139,15 +140,16 @@ get_gbifid <- function(sciname, ask = TRUE, messages = TRUE, rows = NA, assert(rank, "character") assert(method, "character") assert_rows(rows) + pchk(sciname, "sci") - if (inherits(sciname, "character")) { - tstate <- taxon_state$new(class = "gbifid", names = sciname) - items <- sciname + if (inherits(sci, "character")) { + tstate <- taxon_state$new(class = "gbifid", names = sci) + items <- sci } else { - assert_state(sciname, "gbifid") - tstate <- sciname - sciname <- tstate$taxa_remaining() - items <- c(sciname, tstate$taxa_completed()) + assert_state(sci, "gbifid") + tstate <- sci + sci <- tstate$taxa_remaining() + items <- c(sci, tstate$taxa_completed()) } prog <- progressor$new(items = items, suppress = !messages) @@ -155,13 +157,13 @@ get_gbifid <- function(sciname, ask = TRUE, messages = TRUE, rows = NA, for (i in seq_along(done)) prog$completed(names(done)[i], done[[i]]$att) prog$prog_start() - for (i in seq_along(sciname)) { + for (i in seq_along(sci)) { direct <- FALSE - mssg(messages, "\nRetrieving data for taxon '", sciname[i], "'\n") + mssg(messages, "\nRetrieving data for taxon '", sci[i], "'\n") df <- switch( method, - backbone = gbif_name_backbone(sciname[i], ...), - lookup = gbif_name_lookup(sciname[i], ...) + backbone = gbif_name_backbone(sci[i], ...), + lookup = gbif_name_lookup(sci[i], ...) ) mm <- NROW(df) > 1 @@ -186,7 +188,7 @@ get_gbifid <- function(sciname, ask = TRUE, messages = TRUE, rows = NA, if (length(id) > 1) { # check for exact match - matchtmp <- df[as.character(df$canonicalname) %in% sciname[i], "gbifid"] + matchtmp <- df[as.character(df$canonicalname) %in% sci[i], "gbifid"] if (length(matchtmp) == 1) { id <- as.character(matchtmp) direct <- TRUE @@ -222,7 +224,7 @@ get_gbifid <- function(sciname, ask = TRUE, messages = TRUE, rows = NA, # prompt message("\n\n") - message("\nMore than one GBIF ID found for taxon '", sciname[i], "'!\n + message("\nMore than one GBIF ID found for taxon '", sci[i], "'!\n Enter rownumber of taxon (other inputs will return 'NA'):\n") rownames(df) <- 1:nrow(df) print(df) @@ -245,7 +247,7 @@ get_gbifid <- function(sciname, ask = TRUE, messages = TRUE, rows = NA, } } else { if (length(id) != 1) { - warning(sprintf(m_more_than_one_found, "gbifid", sciname[i]), + warning(sprintf(m_more_than_one_found, "gbifid", sci[i]), call. = FALSE) id <- NA_character_ att <- m_na_ask_false @@ -255,9 +257,9 @@ get_gbifid <- function(sciname, ask = TRUE, messages = TRUE, rows = NA, } } res <- list(id = id, att = att, multiple = mm, direct = direct) - prog$completed(sciname[i], att) + prog$completed(sci[i], att) prog$prog(att) - tstate$add(sciname[i], res) + tstate$add(sci[i], res) } out <- tstate$get() ids <- structure(as.character(unlist(pluck(out, "id"))), class = "gbifid", @@ -318,16 +320,20 @@ check_gbifid <- function(x){ #' @export #' @rdname get_gbifid -get_gbifid_ <- function(sciname, messages = TRUE, rows = NA, method = "backbone"){ - setNames(lapply(sciname, get_gbifd_help, messages = messages, rows = rows, method = method), sciname) +get_gbifid_ <- function(sci, messages = TRUE, rows = NA, method = "backbone", + sciname = NULL) { + + pchk(sciname, "sci") + stats::setNames(lapply(sci, get_gbifd_help, messages = messages, + rows = rows, method = method), sci) } -get_gbifd_help <- function(sciname, messages, rows, method){ - mssg(messages, "\nRetrieving data for taxon '", sciname, "'\n") +get_gbifd_help <- function(sci, messages, rows, method){ + mssg(messages, "\nRetrieving data for taxon '", sci, "'\n") df <- switch( method, - backbone = gbif_name_backbone(sciname), - lookup = gbif_name_lookup(sciname) + backbone = gbif_name_backbone(sci), + lookup = gbif_name_lookup(sci) ) if (!is.null(df)) df <- nmslwr(df) sub_rows(df, rows) diff --git a/R/get_ids.R b/R/get_ids.R index 6670094b..d6a183e6 100644 --- a/R/get_ids.R +++ b/R/get_ids.R @@ -9,7 +9,7 @@ get_ids_dbs <- c( #' sources if you like. #' #' @export -#' @param names (character) Taxonomic name to query. +#' @param sci_com (character) Taxonomic name to query. #' @param db (character) database to query. One or more of `ncbi`, `itis`, `eol`, #' `tropicos`, `gbif`, `nbn`, or `pow`. By default db is set to search #' all data sources. Note that each taxonomic data source has their own @@ -24,6 +24,7 @@ get_ids_dbs <- c( #' gives back a ids class object with one to many identifiers. See #' `get_ids_` to get back all, or a subset, of the raw data that you #' are presented during the ask process. +#' @param names Deprecated, see `sci_com` #' @param ... Other arguments passed to [get_tsn()], [get_uid()], #' [get_eolid()], [get_tpsid()], [get_gbifid()], #' [get_nbnid()]. @@ -41,27 +42,27 @@ get_ids_dbs <- c( #' @examples \dontrun{ #' # Plug in taxon names directly #' ## By default you get ids for all data sources -#' get_ids(names="Chironomus riparius") +#' get_ids("Chironomus riparius") #' #' # specify rows to limit choices available -#' get_ids(names="Poa annua", db="eol", rows=1) -#' get_ids(names="Poa annua", db="eol", rows=1:2) +#' get_ids("Poa annua", db="eol", rows=1) +#' get_ids("Poa annua", db="eol", rows=1:2) #' #' ## Or you can specify which source you want via the db parameter -#' get_ids(names="Chironomus riparius", db = 'ncbi') -#' get_ids(names="Salvelinus fontinalis", db = 'nbn') +#' get_ids("Chironomus riparius", db = 'ncbi') +#' get_ids("Salvelinus fontinalis", db = 'nbn') #' -#' get_ids(names=c("Chironomus riparius", "Pinus contorta"), db = 'ncbi') -#' get_ids(names=c("Chironomus riparius", "Pinus contorta"), +#' get_ids(c("Chironomus riparius", "Pinus contorta"), db = 'ncbi') +#' get_ids(c("Chironomus riparius", "Pinus contorta"), #' db = c('ncbi','itis')) -#' get_ids(names=c("Chironomus riparius", "Pinus contorta"), +#' get_ids(c("Chironomus riparius", "Pinus contorta"), #' db = c('ncbi','itis')) -#' get_ids(names="Pinus contorta", +#' get_ids("Pinus contorta", #' db = c('ncbi','itis','eol','tropicos')) -#' get_ids(names="ava avvva", db = c('ncbi','itis','eol','tropicos')) +#' get_ids("ava avvva", db = c('ncbi','itis','eol','tropicos')) #' #' # Pass on to other functions -#' out <- get_ids(names="Pinus contorta", +#' out <- get_ids("Pinus contorta", #' db = c('ncbi','itis','eol','tropicos')) #' classification(out$itis) #' synonyms(out$tropicos) @@ -76,28 +77,28 @@ get_ids_dbs <- c( #' get_ids("Agapostemon", db = "ncbi", verbose = TRUE) #' } -get_ids <- function(names, +get_ids <- function(sci_com, db = c("itis", "ncbi", "eol", "tropicos", "gbif", "nbn", - "pow"), suppress = FALSE, ...) { + "pow"), suppress = FALSE, names = NULL, ...) { assert(suppress, "logical") if (is.null(db)) stop("Must specify one or more values for db!") db <- match.arg(db, choices = get_ids_dbs, several.ok = TRUE) - foo <- function(x, names, ...){ + foo <- function(x, sci_com, ...){ if (!suppress) cat_db(x) ids <- switch(x, - itis = get_tsn(names, ...), - ncbi = get_uid(names, ...), - eol = get_eolid(names, ...), - tropicos = get_tpsid(names, ...), - gbif = get_gbifid(names, ...), - nbn = get_nbnid(names, ...), - pow = get_pow(names, ...)) - names(ids) <- names + itis = get_tsn(sci_com, ...), + ncbi = get_uid(sci_com, ...), + eol = get_eolid(sci_com, ...), + tropicos = get_tpsid(sci_com, ...), + gbif = get_gbifid(sci_com, ...), + nbn = get_nbnid(sci_com, ...), + pow = get_pow(sci_com, ...)) + names(ids) <- sci_com return( ids ) } - tmp <- lapply(db, function(x) foo(x, names = names, ...)) + tmp <- lapply(db, function(x) foo(x, sci_com = sci_com, ...)) names(tmp) <- db class(tmp) <- "ids" return( tmp ) @@ -105,24 +106,24 @@ get_ids <- function(names, #' @export #' @rdname get_ids -get_ids_ <- function(names, db = get_ids_dbs, rows = NA, - suppress = FALSE, ...) { +get_ids_ <- function(sci_com, db = get_ids_dbs, rows = NA, + suppress = FALSE, names = NULL, ...) { if (is.null(db)) stop("Must specify on or more values for db!") db <- match.arg(db, choices = get_ids_dbs, several.ok = TRUE) - foo <- function(x, names, rows, ...){ + foo <- function(x, sci_com, rows, ...){ if (!suppress) cat_db(x) ids <- switch(x, - itis = get_tsn_(names, rows = rows, ...), - ncbi = get_uid_(names, rows = rows, ...), - eol = get_eolid_(names, rows = rows, ...), - tropicos = get_tpsid_(names, rows = rows, ...), - gbif = get_gbifid_(names, rows = rows, ...), - nbn = get_nbnid_(names, rows = rows, ...)) - stats::setNames(ids, names) + itis = get_tsn_(sci_com, rows = rows, ...), + ncbi = get_uid_(sci_com, rows = rows, ...), + eol = get_eolid_(sci_com, rows = rows, ...), + tropicos = get_tpsid_(sci_com, rows = rows, ...), + gbif = get_gbifid_(sci_com, rows = rows, ...), + nbn = get_nbnid_(sci_com, rows = rows, ...)) + stats::setNames(ids, sci_com) } structure(stats::setNames( - lapply(db, function(x) foo(x, names = names, rows = rows, ...)), db), + lapply(db, function(x) foo(x, sci_com = sci_com, rows = rows, ...)), db), class = "ids") } diff --git a/R/get_iucn.R b/R/get_iucn.R index d42fb45c..71c24f69 100644 --- a/R/get_iucn.R +++ b/R/get_iucn.R @@ -1,7 +1,7 @@ #' Get a IUCN Redlist taxon #' #' @export -#' @param x (character) A vector of scientific names. Or, a +#' @param sci (character) A vector of scientific names. Or, a #' `taxon_state` object (see [taxon-state]) #' @param messages logical; should progress be printed? #' @param key (character) required. you IUCN Redlist API key. See @@ -9,6 +9,8 @@ #' IUCN Redlist #' @param check (logical) Check if ID matches any existing on the DB, only #' used in [as.iucn()] +#' @param x For `get_iucn()`: Deprecated, see `sci`. For `as.iucn()`, various, +#' see examples #' @param ... Ignored #' #' @return A vector of taxonomic identifiers as an S3 class. @@ -39,9 +41,9 @@ #' @family taxonomic-ids #' #' @examples \dontrun{ -#' get_iucn(x = "Branta canadensis") -#' get_iucn(x = "Branta bernicla") -#' get_iucn(x = "Panthera uncia") +#' get_iucn("Branta canadensis") +#' get_iucn("Branta bernicla") +#' get_iucn("Panthera uncia") #' #' # as coercion #' as.iucn(22732) @@ -50,19 +52,20 @@ #' data.frame(res) #' as.iucn(data.frame(res)) #' } -get_iucn <- function(x, messages = TRUE, key = NULL, ...) { +get_iucn <- function(sci, messages = TRUE, key = NULL, x = NULL, ...) { - assert(x, c("character", "taxon_state")) + assert(sci, c("character", "taxon_state")) assert(messages, "logical") + pchk(x, "sci") - if (inherits(x, "character")) { - tstate <- taxon_state$new(class = "iucn", names = x) - items <- x + if (inherits(sci, "character")) { + tstate <- taxon_state$new(class = "iucn", names = sci) + items <- sci } else { - assert_state(x, "iucn") - tstate <- x - x <- tstate$taxa_remaining() - items <- c(x, tstate$taxa_completed()) + assert_state(sci, "iucn") + tstate <- sci + sci <- tstate$taxa_remaining() + items <- c(sci, tstate$taxa_completed()) } prog <- progressor$new(items = items, suppress = !messages) @@ -70,10 +73,10 @@ get_iucn <- function(x, messages = TRUE, key = NULL, ...) { for (i in seq_along(done)) prog$completed(names(done)[i], done[[i]]$att) prog$prog_start() - for (i in seq_along(x)) { + for (i in seq_along(sci)) { direct <- FALSE - mssg(messages, "\nRetrieving data for taxon '", x[i], "'\n") - df <- rredlist::rl_search(x[i], key = key, ...) + mssg(messages, "\nRetrieving data for taxon '", sci[i], "'\n") + df <- rredlist::rl_search(sci[i], key = key, ...) if (!inherits(df$result, "data.frame") || NROW(df$result) == 0) { id <- NA_character_ @@ -90,7 +93,7 @@ get_iucn <- function(x, messages = TRUE, key = NULL, ...) { } # check for direct match - direct <- match(tolower(df$scientific_name), tolower(x[i])) + direct <- match(tolower(df$scientific_name), tolower(sci[i])) if (!all(is.na(direct))) { id <- df$taxonid[!is.na(direct)] @@ -103,10 +106,10 @@ get_iucn <- function(x, messages = TRUE, key = NULL, ...) { } # multiple matches not possible because no real search } - res <- list(id = id, name = x[i], att = att, direct = direct) - prog$completed(x[i], att) + res <- list(id = id, name = sci[i], att = att, direct = direct) + prog$completed(sci[i], att) prog$prog(att) - tstate$add(x[i], res) + tstate$add(sci[i], res) } out <- tstate$get() ids <- structure(as.character(unlist(pluck(out, "id"))), class = "iucn", diff --git a/R/get_natservid.R b/R/get_natservid.R index 391d5a9b..c9d522e5 100644 --- a/R/get_natservid.R +++ b/R/get_natservid.R @@ -1,7 +1,7 @@ #' Get NatureServe taxonomic ID for a taxon name #' #' @export -#' @param query character; A vector of common or scientific names. Or, a +#' @param sci_com character; A vector of common or scientific names. Or, a #' `taxon_state` object (see [taxon-state]) #' @param searchtype character; One of 'scientific' (default) or 'common'. #' This doesn't affect the query to NatureServe - but rather affects what @@ -17,6 +17,7 @@ #' `get_natservid_()` to get back all, or a subset, of the raw #' data that you are presented during the ask process. #' @param x Input to `as.natservid` +#' @param query Deprecated, see `sci_com` #' @param ... curl options passed on to [crul::verb-POST] #' @param check logical; Check if ID matches any existing on the DB, only #' used in [as.natservid()] @@ -70,24 +71,25 @@ #' get_natservid_("Ruby*", searchtype = "common") #' get_natservid_("Ruby*", searchtype = "common", rows=1:3) #' } -get_natservid <- function(query, searchtype = "scientific", ask = TRUE, - messages = TRUE, rows = NA, ...) { +get_natservid <- function(sci_com, searchtype = "scientific", ask = TRUE, + messages = TRUE, rows = NA, query = NULL, ...) { - assert(query, c("character", "taxon_state")) + assert(sci_com, c("character", "taxon_state")) assert(ask, "logical") assert(searchtype, "character") assert(ask, "logical") assert(messages, "logical") assert_rows(rows) + pchk(query, "sci_com") - if (inherits(query, "character")) { - tstate <- taxon_state$new(class = "natservid", names = query) - items <- query + if (inherits(sci_com, "character")) { + tstate <- taxon_state$new(class = "natservid", names = sci_com) + items <- sci_com } else { - assert_state(query, "natservid") - tstate <- query - query <- tstate$taxa_remaining() - items <- c(query, tstate$taxa_completed()) + assert_state(sci_com, "natservid") + tstate <- sci_com + sci_com <- tstate$taxa_remaining() + items <- c(sci_com, tstate$taxa_completed()) } prog <- progressor$new(items = items, suppress = !messages) @@ -95,16 +97,16 @@ get_natservid <- function(query, searchtype = "scientific", ask = TRUE, for (i in seq_along(done)) prog$completed(names(done)[i], done[[i]]$att) prog$prog_start() - for (i in seq_along(query)) { + for (i in seq_along(sci_com)) { direct <- FALSE - mssg(messages, "\nRetrieving data for taxon '", query[i], "'\n") + mssg(messages, "\nRetrieving data for taxon '", sci_com[i], "'\n") if (!searchtype %in% c("scientific", "common")) { stop("'searchtype' must be one of 'scientific' or 'common'", call. = FALSE) } - nsdf <- ns_worker(x = query[i], searchtype = searchtype, ...) + nsdf <- ns_worker(x = sci_com[i], searchtype = searchtype, ...) mm <- NROW(nsdf) > 1 if (!inherits(nsdf, "tbl_df") || NROW(nsdf) == 0) { @@ -131,7 +133,7 @@ get_natservid <- function(query, searchtype = "scientific", ask = TRUE, if (nrow(nsdf) > 1) { names(nsdf)[grep(searchtype, names(nsdf))] <- "target" - direct <- match(tolower(nsdf$target), tolower(query[i])) + direct <- match(tolower(nsdf$target), tolower(sci_com[i])) if (length(direct) == 1) { if (!all(is.na(direct))) { @@ -166,7 +168,7 @@ get_natservid <- function(query, searchtype = "scientific", ask = TRUE, message("\n\n") rownames(nsdf) <- seq_len(NROW(nsdf)) print(nsdf) - message("\nMore than one NatureServe ID found for taxon '", query[i], "'!\n + message("\nMore than one NatureServe ID found for taxon '", sci_com[i], "'!\n Enter rownumber of taxon (other inputs will return 'NA'):\n") # prompt take <- scan(n = 1, quiet = TRUE, what = 'raw') @@ -186,7 +188,7 @@ get_natservid <- function(query, searchtype = "scientific", ask = TRUE, } } else { if (length(nsid) != 1) { - warning(sprintf(m_more_than_one_found, "NatureServe ID", query[i]), + warning(sprintf(m_more_than_one_found, "NatureServe ID", sci_com[i]), call. = FALSE) nsid <- NA_character_ att <- m_na_ask_false @@ -197,9 +199,9 @@ get_natservid <- function(query, searchtype = "scientific", ask = TRUE, } res <- list(id = as.character(nsid), att = att, multiple = mm, direct = direct) - prog$completed(query[i], att) + prog$completed(sci_com[i], att) prog$prog(att) - tstate$add(query[i], res) + tstate$add(sci_com[i], res) } out <- tstate$get() ids <- structure(as.character(unlist(pluck(out, "id"))), class = "natservid", @@ -261,19 +263,20 @@ check_natservid <- function(x){ #' @export #' @rdname get_natservid -get_natservid_ <- function(query, searchtype = "scientific", messages = TRUE, - rows = NA, ...) { +get_natservid_ <- function(sci_com, searchtype = "scientific", messages = TRUE, + rows = NA, query = NULL, ...) { + pchk(query, "sci_com") stats::setNames( - lapply(query, get_natservid_help, searchtype = searchtype, + lapply(sci_com, get_natservid_help, searchtype = searchtype, messages = messages, rows = rows, ...), - query + sci_com ) } -get_natservid_help <- function(query, searchtype, messages, rows, ...) { - mssg(messages, "\nRetrieving data for taxon '", query, "'\n") - df <- ns_worker(x = query, searchtype = searchtype, ...) +get_natservid_help <- function(sci_com, searchtype, messages, rows, ...) { + mssg(messages, "\nRetrieving data for taxon '", sci_com, "'\n") + df <- ns_worker(x = sci_com, searchtype = searchtype, ...) sub_rows(df, rows) } diff --git a/R/get_nbnid.R b/R/get_nbnid.R index ccc3af27..2caf397a 100644 --- a/R/get_nbnid.R +++ b/R/get_nbnid.R @@ -1,7 +1,7 @@ #' Get the UK National Biodiversity Network ID from taxonomic names. #' #' @export -#' @param name character; a vector of common or scientific names. Or, a +#' @param sci_com character; a vector of common or scientific names. Or, a #' `taxon_state` object (see [taxon-state]) #' @param ask logical; should get_nbnid be run in interactive mode? #' If TRUE and more than one ID is found for the species, the user is asked for @@ -18,6 +18,7 @@ #' class object with one to many identifiers. See #' [get_nbnid_()] to get back all, or a subset, of the raw #' data that you are presented during the ask process. +#' @param name Deprecated, see `sci_com` #' @param ... Further args passed on to `nbn_search` #' @param x Input to [as.nbnid()] #' @param check logical; Check if ID matches any existing on the DB, only @@ -35,14 +36,14 @@ #' @author Scott Chamberlain, \email{myrmecocystus@@gmail.com} #' #' @examples \dontrun{ -#' get_nbnid(name='Poa annua') -#' get_nbnid(name='Poa annua', rec_only=TRUE) -#' get_nbnid(name='Poa annua', rank='Species') -#' get_nbnid(name='Poa annua', rec_only=TRUE, rank='Species') -#' get_nbnid(name='Pinus contorta') +#' get_nbnid(sci_com='Poa annua') +#' get_nbnid(sci_com='Poa annua', rec_only=TRUE) +#' get_nbnid(sci_com='Poa annua', rank='Species') +#' get_nbnid(sci_com='Poa annua', rec_only=TRUE, rank='Species') +#' get_nbnid(sci_com='Pinus contorta') #' #' # The NBN service handles common names too -#' get_nbnid(name='red-winged blackbird') +#' get_nbnid(sci_com='red-winged blackbird') #' #' # specify rows to limit choices available #' get_nbnid('Poa ann') @@ -51,7 +52,7 @@ #' get_nbnid('Poa ann', rows=1:2) #' #' # When not found -#' get_nbnid(name="uaudnadndj") +#' get_nbnid(sci_com="uaudnadndj") #' get_nbnid(c("Zootoca vivipara", "uaudnadndj")) #' get_nbnid(c("Zootoca vivipara","Chironomus riparius", "uaudnadndj")) #' @@ -83,24 +84,25 @@ #' invisible(get_nbnid("Quercus douglasii", verbose = TRUE)) #' } -get_nbnid <- function(name, ask = TRUE, messages = TRUE, rec_only = FALSE, - rank = NULL, rows = NA, ...){ +get_nbnid <- function(sci_com, ask = TRUE, messages = TRUE, rec_only = FALSE, + rank = NULL, rows = NA, name = NULL, ...) { - assert(name, c("character", "taxon_state")) + assert(sci_com, c("character", "taxon_state")) assert(ask, "logical") assert(rec_only, "logical") assert(rank, "character") assert(messages, "logical") assert_rows(rows) + pchk(name, "sci_com") - if (inherits(name, "character")) { - tstate <- taxon_state$new(class = "nbnid", names = name) - items <- name + if (inherits(sci_com, "character")) { + tstate <- taxon_state$new(class = "nbnid", names = sci_com) + items <- sci_com } else { - assert_state(name, "nbnid") - tstate <- name - name <- tstate$taxa_remaining() - items <- c(name, tstate$taxa_completed()) + assert_state(sci_com, "nbnid") + tstate <- sci_com + sci_com <- tstate$taxa_remaining() + items <- c(sci_com, tstate$taxa_completed()) } prog <- progressor$new(items = items, suppress = !messages) @@ -108,10 +110,10 @@ get_nbnid <- function(name, ask = TRUE, messages = TRUE, rec_only = FALSE, for (i in seq_along(done)) prog$completed(names(done)[i], done[[i]]$att) prog$prog_start() - for (i in seq_along(name)) { + for (i in seq_along(sci_com)) { direct <- FALSE - mssg(messages, "\nRetrieving data for taxon '", name[i], "'\n") - df <- nbn_search(q = name[i], rows = 500, fq = "idxtype:TAXON", + mssg(messages, "\nRetrieving data for taxon '", sci_com[i], "'\n") + df <- nbn_search(sci_com = sci_com[i], rows = 500, fq = "idxtype:TAXON", ...)$data if (is.null(df) || length(df) == 0) df <- data.frame(NULL) mm <- NROW(df) > 1 @@ -140,7 +142,7 @@ get_nbnid <- function(name, ask = TRUE, messages = TRUE, rec_only = FALSE, } # more than one, try for direct match if (length(id) > 1) { - matchtmp <- df[tolower(df$scientificName) %in% tolower(name[i]),] + matchtmp <- df[tolower(df$scientificName) %in% tolower(sci_com[i]),] if (NROW(matchtmp) == 1) { id <- matchtmp$nbnid rank_taken <- as.character(matchtmp$rank) @@ -155,7 +157,7 @@ get_nbnid <- function(name, ask = TRUE, messages = TRUE, rec_only = FALSE, rownames(df) <- seq_len(NROW(df)) # prompt message("\n\n") - message("\nMore than one NBN ID found for taxon '", name[i], "'!\n + message("\nMore than one NBN ID found for taxon '", sci_com[i], "'!\n Enter rownumber of taxon (other inputs will return 'NA'):\n") print(df) take <- scan(n = 1, quiet = TRUE, what = 'raw') @@ -178,7 +180,7 @@ get_nbnid <- function(name, ask = TRUE, messages = TRUE, rec_only = FALSE, } } else{ if (length(id) != 1) { - warning(sprintf(m_more_than_one_found, "NBN ID", name[i]), + warning(sprintf(m_more_than_one_found, "NBN ID", sci_com[i]), call. = FALSE) id <- NA_character_ att <- m_na_ask_false @@ -188,9 +190,9 @@ get_nbnid <- function(name, ask = TRUE, messages = TRUE, rec_only = FALSE, # list(id = id, rank = rank_taken, att = att, multiple = mm, direct = direct) res <- list(id = id, rank = rank_taken, att = att, multiple = mm, direct = direct) - prog$completed(name[i], att) + prog$completed(sci_com[i], att) prog$prog(att) - tstate$add(name[i], res) + tstate$add(sci_com[i], res) } # name <- as.character(name) # out <- lapply(name, fun, ask = ask, messages = messages, rows = rows, ...) @@ -279,15 +281,16 @@ check_nbnid <- function(x){ #' @export #' @rdname get_nbnid -get_nbnid_ <- function(name, messages = TRUE, rec_only = FALSE, rank = NULL, - rows = NA, ...) { - stats::setNames(lapply(name, get_nbnid_help, messages = messages, - rec_only = rec_only, rank = rank, rows = rows, ...), name) +get_nbnid_ <- function(sci_com, messages = TRUE, rec_only = FALSE, rank = NULL, + rows = NA, name = NULL, ...) { + pchk(name, "sci_com") + stats::setNames(lapply(sci_com, get_nbnid_help, messages = messages, + rec_only = rec_only, rank = rank, rows = rows, ...), sci_com) } get_nbnid_help <- function(name, messages, rec_only, rank, rows, ...){ mssg(messages, "\nRetrieving data for taxon '", name, "'\n") - df <- nbn_search(q = name, all = TRUE, ...)$data + df <- nbn_search(sci_com = name, all = TRUE, ...)$data if (is.null(df)) df <- data.frame(NULL) if (NROW(df) == 0) { diff --git a/R/get_pow.R b/R/get_pow.R index b6ecf44c..a24c02a5 100644 --- a/R/get_pow.R +++ b/R/get_pow.R @@ -1,7 +1,7 @@ #' Get Kew's Plants of the World code for a taxon #' #' @export -#' @param x character; A vector of common or scientific names. Or, a +#' @param sci_com character; A vector of common or scientific names. Or, a #' `taxon_state` object (see [taxon-state]) #' @param accepted logical; If TRUE, removes names that are not accepted #' valid names by ITIS. Set to `FALSE` (default) to give back both @@ -10,6 +10,8 @@ #' If TRUE and more than one pow is found for teh species, the user is #' asked for input. If FALSE NA is returned for multiple matches. #' @param messages logical; should progress be printed? +#' @param x For `get_pow()`: deprecated, see `sci_com`. For `as.pow`, various, +#' see examples #' @param ... Curl options passed on to [crul::HttpClient] #' @param rows numeric; Any number from 1 to infinity. If the default NA, #' all rows are considered. Note that this function still only gives back @@ -39,12 +41,12 @@ #' @seealso [classification()] #' #' @examples \dontrun{ -#' get_pow(x = "Helianthus") +#' get_pow(sci_com="Helianthus") #' get_pow(c("Helianthus","Quercus douglasii")) #' #' # Get back a subset -#' get_pow(x="Helianthus", rows = 1) -#' get_pow(x="Helianthus", rows = 1:10) +#' get_pow(sci_com="Helianthus", rows = 1) +#' get_pow(sci_com="Helianthus", rows = 1:10) #' #' # When not found #' get_pow("howdy") @@ -85,25 +87,26 @@ #' get_pow_(c("Pinus", "Abies"), rows = 1:3) #' } -get_pow <- function(x, accepted = FALSE, ask = TRUE, messages = TRUE, - rows = NA, family_filter = NULL, rank_filter = NULL, ...) { +get_pow <- function(sci_com, accepted = FALSE, ask = TRUE, messages = TRUE, + rows = NA, family_filter = NULL, rank_filter = NULL, x = NULL, ...) { - assert(x, c("character", "taxon_state")) + assert(sci_com, c("character", "taxon_state")) assert(accepted, "logical") assert(ask, "logical") assert(messages, "logical") assert(family_filter, "character") assert(rank_filter, "character") assert_rows(rows) + pchk(x, "sci_com") - if (inherits(x, "character")) { - tstate <- taxon_state$new(class = "pow", names = x) - items <- x + if (inherits(sci_com, "character")) { + tstate <- taxon_state$new(class = "pow", names = sci_com) + items <- sci_com } else { - assert_state(x, "pow") - tstate <- x - x <- tstate$taxa_remaining() - items <- c(x, tstate$taxa_completed()) + assert_state(sci_com, "pow") + tstate <- sci_com + sci_com <- tstate$taxa_remaining() + items <- c(sci_com, tstate$taxa_completed()) } prog <- progressor$new(items = items, suppress = !messages) @@ -111,10 +114,10 @@ get_pow <- function(x, accepted = FALSE, ask = TRUE, messages = TRUE, for (i in seq_along(done)) prog$completed(names(done)[i], done[[i]]$att) prog$prog_start() - for (i in seq_along(x)) { + for (i in seq_along(sci_com)) { direct <- FALSE - mssg(messages, "\nRetrieving data for taxon '", x[i], "'\n") - pow_df <- pow_search(q = x[i], ...)$data + mssg(messages, "\nRetrieving data for taxon '", sci_com[i], "'\n") + pow_df <- pow_search(sci_com = sci_com[i], ...)$data mm <- NROW(pow_df) > 1 if (!inherits(pow_df, "data.frame")) { @@ -142,7 +145,7 @@ get_pow <- function(x, accepted = FALSE, ask = TRUE, messages = TRUE, # check for direct match if (nrow(pow_df) > 1) { names(pow_df)[grep('name', names(pow_df))] <- "target" - di_rect <- pow_df[tolower(pow_df$target) %in% tolower(x[i]), "fqId"] + di_rect <- pow_df[tolower(pow_df$target) %in% tolower(sci_com[i]), "fqId"] if (length(di_rect) == 1) { pow <- di_rect direct <- TRUE @@ -180,7 +183,7 @@ get_pow <- function(x, accepted = FALSE, ask = TRUE, messages = TRUE, # prompt message("\n\n") print(pow_df) - message("\nMore than one pow found for taxon '", x[i], "'!\n + message("\nMore than one pow found for taxon '", sci_com[i], "'!\n Enter rownumber of taxon (other inputs will return 'NA'):\n") # prompt take <- scan(n = 1, quiet = TRUE, what = 'raw') @@ -203,7 +206,7 @@ get_pow <- function(x, accepted = FALSE, ask = TRUE, messages = TRUE, } else { warning( sprintf("More than one pow found for taxon '%s'; refine query or set ask=TRUE", - x[i]), + sci_com[i]), call. = FALSE ) pow <- NA_character_ @@ -214,9 +217,9 @@ get_pow <- function(x, accepted = FALSE, ask = TRUE, messages = TRUE, } res <- list(id = as.character(pow), att = att, multiple = mm, direct = direct) - prog$completed(x[i], att) + prog$completed(sci_com[i], att) prog$prog(att) - tstate$add(x[i], res) + tstate$add(sci_com[i], res) } out <- tstate$get() ids <- structure(as.character(unlist(pluck(out, "id"))), class = "pow", @@ -275,12 +278,14 @@ check_pow <- function(x){ #' @export #' @rdname get_pow -get_pow_ <- function(x, messages = TRUE, rows = NA, ...){ - stats::setNames(lapply(x, get_pow_help, messages = messages, rows = rows, ...), x) +get_pow_ <- function(sci_com, messages = TRUE, rows = NA, x = NULL, ...) { + pchk(x, "sci_com") + stats::setNames(lapply(sci_com, get_pow_help, messages = messages, + rows = rows, ...), sci_com) } get_pow_help <- function(x, messages, rows, ...){ mssg(messages, "\nRetrieving data for taxon '", x, "'\n") - df <- pow_search(q = x, ...)$data + df <- pow_search(sci_com = x, ...)$data if (NROW(df) == 0) NULL else sub_rows(df, rows) } diff --git a/R/get_tolid.R b/R/get_tolid.R index 50699f33..3751a202 100644 --- a/R/get_tolid.R +++ b/R/get_tolid.R @@ -4,7 +4,7 @@ #' OpenTreeOfLife #' #' @export -#' @param sciname character; one or more scientific names. Or, a `taxon_state` +#' @param sci character; one or more scientific names. Or, a `taxon_state` #' object (see [taxon-state]) #' @param ask logical; should `get_tolid` be run in interactive mode? #' If `TRUE` and more than one TOL is found for the species, the user is @@ -16,6 +16,7 @@ #' to get back all, or a subset, of the raw data that you are presented during #' the ask process. #' @param x Input to `as.tolid` +#' @param sciname Deprecated, see `sci` #' @param ... Ignored #' @param check logical; Check if ID matches any existing on the DB, only #' used in [as.tolid()] @@ -25,8 +26,8 @@ #' @seealso [classification()] #' #' @examples \dontrun{ -#' get_tolid(sciname = "Quercus douglasii") -#' get_tolid(sciname = "Chironomus riparius") +#' get_tolid(sci = "Quercus douglasii") +#' get_tolid(sci = "Chironomus riparius") #' get_tolid(c("Chironomus riparius","Quercus douglasii")) #' splist <- c("annona cherimola", 'annona muricata', "quercus robur", #' "shorea robusta", "pandanus patina", "oryza sativa", "durio zibethinus") @@ -60,30 +61,32 @@ #' as.tolid( data.frame(out) ) #' #' # Get all data back -#' get_tolid_(sciname="Arni") +#' get_tolid_("Arni") #' get_tolid_("Arni", rows=1) #' get_tolid_("Arni", rows=1:2) #' get_tolid_(c("asdfadfasd","Pinus contorta")) #' } -get_tolid <- function(sciname, ask = TRUE, messages = TRUE, rows = NA, ...) { +get_tolid <- function(sci, ask = TRUE, messages = TRUE, rows = NA, + sciname = NULL, ...) { - assert(sciname, c("character", "taxon_state")) + assert(sci, c("character", "taxon_state")) assert(ask, "logical") assert(messages, "logical") + pchk(sciname, "sci") if (!all(is.na(rows))) { assert(rows, c("numeric", "integer")) stopifnot(rows > 0) } - if (inherits(sciname, "character")) { - tstate <- taxon_state$new(class = "tolid", names = sciname) - items <- sciname + if (inherits(sci, "character")) { + tstate <- taxon_state$new(class = "tolid", names = sci) + items <- sci } else { - assert_state(sciname, "tolid") - tstate <- sciname - sciname <- tstate$taxa_remaining() - items <- c(sciname, tstate$taxa_completed()) + assert_state(sci, "tolid") + tstate <- sci + sci <- tstate$taxa_remaining() + items <- c(sci, tstate$taxa_completed()) } prog <- progressor$new(items = items, suppress = !messages) @@ -91,10 +94,10 @@ get_tolid <- function(sciname, ask = TRUE, messages = TRUE, rows = NA, ...) { for (i in seq_along(done)) prog$completed(names(done)[i], done[[i]]$att) prog$prog_start() - for (i in seq_along(sciname)) { - mssg(messages, "\nRetrieving data for taxon '", sciname[i], "'\n") + for (i in seq_along(sci)) { + mssg(messages, "\nRetrieving data for taxon '", sci[i], "'\n") - tol_df <- tryCatch(tol_resolve(sciname[i], ...), error = function(e) e) + tol_df <- tryCatch(tol_resolve(sci[i], ...), error = function(e) e) if ( !inherits(tol_df, "data.frame") || @@ -123,7 +126,7 @@ get_tolid <- function(sciname, ask = TRUE, messages = TRUE, rows = NA, ...) { # more than one found -> user input if (NROW(tol_df) > 1) { # check for exact match - matchtmp <- tol_df[tolower(tol_df$unique_name) %in% tolower(sciname[i]), "ott_id"] + matchtmp <- tol_df[tolower(tol_df$unique_name) %in% tolower(sci[i]), "ott_id"] if (length(matchtmp) == 1) { id <- as.character(matchtmp) direct <- TRUE @@ -145,7 +148,7 @@ get_tolid <- function(sciname, ask = TRUE, messages = TRUE, rows = NA, ...) { if (ask) { # prompt message("\n\n") - message("\nMore than one ToL ID found for taxon '", sciname[i], "'!\n + message("\nMore than one ToL ID found for taxon '", sci[i], "'!\n Enter rownumber of taxon (other inputs will return 'NA'):\n") rownames(tol_df) <- 1:nrow(tol_df) print(tol_df) @@ -169,7 +172,7 @@ get_tolid <- function(sciname, ask = TRUE, messages = TRUE, rows = NA, ...) { } else { if (length(id) != 1) { - warning(sprintf(m_more_than_one_found, "ToL ID", sciname[i]), + warning(sprintf(m_more_than_one_found, "ToL ID", sci[i]), call. = FALSE) id <- NA_character_ att <- m_na_ask_false @@ -181,9 +184,9 @@ get_tolid <- function(sciname, ask = TRUE, messages = TRUE, rows = NA, ...) { } res <- list(id = as.character(id), att = att, multiple = FALSE, direct = FALSE) - prog$completed(sciname[i], att) + prog$completed(sci[i], att) prog$prog(att) - tstate$add(sciname[i], res) + tstate$add(sci[i], res) } out <- tstate$get() ids <- structure(as.character(unlist(pluck(out, "id"))), class = "tolid", @@ -250,16 +253,17 @@ check_tolid <- function(x){ #' @export #' @rdname get_tolid -get_tolid_ <- function(sciname, messages = TRUE, rows = NA){ +get_tolid_ <- function(sci, messages = TRUE, rows = NA, sciname = NULL) { + pchk(sciname, "sci") stats::setNames( - lapply(sciname, get_tolid_help, messages = messages, rows = rows), - sciname + lapply(sci, get_tolid_help, messages = messages, rows = rows), + sci ) } -get_tolid_help <- function(sciname, messages, rows, ...){ - mssg(messages, "\nRetrieving data for taxon '", sciname, "'\n") - tol_df <- tryCatch(tol_resolve(sciname, ...), error = function(e) e) +get_tolid_help <- function(sci, messages, rows, ...){ + mssg(messages, "\nRetrieving data for taxon '", sci, "'\n") + tol_df <- tryCatch(tol_resolve(sci, ...), error = function(e) e) if (!inherits(tol_df, "data.frame") || NROW(tol_df) == 0 || inherits(tol_df, "error")) { NULL } else { diff --git a/R/get_tpsid.R b/R/get_tpsid.R index 66f023a9..d4a297c7 100644 --- a/R/get_tpsid.R +++ b/R/get_tpsid.R @@ -1,7 +1,7 @@ #' Get the NameID codes from Tropicos for taxonomic names. #' #' @export -#' @param sciname (character) One or more scientific name's as a vector or list. Or, +#' @param sci (character) One or more scientific name's as a vector or list. Or, #' a `taxon_state` object (see [taxon-state]) #' @param ask logical; should get_tpsid be run in interactive mode? #' If TRUE and more than one ID is found for the species, the user is asked for @@ -16,6 +16,7 @@ #' @param rank (character) A taxonomic rank name. See [rank_ref()] for possible #' options. Though note that some data sources use atypical ranks, so inspect the #' data itself for options. Optional. See `Filtering` below. +#' @param sciname Deprecated, see `sci` #' @param ... Other arguments passed to [tp_search()]. #' @param x Input to [as.tpsid()] #' @param check logical; Check if ID matches any existing on the DB, only used in @@ -35,8 +36,8 @@ #' @author Scott Chamberlain, \email{myrmecocystus@@gmail.com} #' #' @examples \dontrun{ -#' get_tpsid(sciname='Poa annua') -#' get_tpsid(sciname='Pinus contorta') +#' get_tpsid(sci='Poa annua') +#' get_tpsid(sci='Pinus contorta') #' #' get_tpsid(c("Poa annua", "Pinus contorta")) #' @@ -70,7 +71,7 @@ #' get_tpsid("Aga", fuzzy = TRUE, parent = "*idae") #' #' # pass to classification function to get a taxonomic hierarchy -#' classification(get_tpsid(sciname='Poa annua')) +#' classification(get_tpsid(sci='Poa annua')) #' #' # Convert a tpsid without class information to a tpsid class #' as.tpsid(get_tpsid("Pinus contorta")) # already a tpsid, returns the same @@ -100,24 +101,25 @@ #' invisible(get_tpsid("Quercus douglasii", messages = TRUE)) #' } -get_tpsid <- function(sciname, ask = TRUE, messages = TRUE, key = NULL, - rows = NA, family = NULL, rank = NULL, ...) { +get_tpsid <- function(sci, ask = TRUE, messages = TRUE, key = NULL, + rows = NA, family = NULL, rank = NULL, sciname = NULL, ...) { - assert(sciname, c("character", "taxon_state")) + assert(sci, c("character", "taxon_state")) assert(ask, "logical") assert(messages, "logical") assert(family, "character") assert(rank, "character") assert_rows(rows) + pchk(sciname, "sci") - if (inherits(sciname, "character")) { - tstate <- taxon_state$new(class = "tpsid", names = sciname) - items <- sciname + if (inherits(sci, "character")) { + tstate <- taxon_state$new(class = "tpsid", names = sci) + items <- sci } else { - assert_state(sciname, "tpsid") - tstate <- sciname - sciname <- tstate$taxa_remaining() - items <- c(sciname, tstate$taxa_completed()) + assert_state(sci, "tpsid") + tstate <- sci + sci <- tstate$taxa_remaining() + items <- c(sci, tstate$taxa_completed()) } prog <- progressor$new(items = items, suppress = !messages) @@ -125,10 +127,10 @@ get_tpsid <- function(sciname, ask = TRUE, messages = TRUE, key = NULL, for (i in seq_along(done)) prog$completed(names(done)[i], done[[i]]$att) prog$prog_start() - for (i in seq_along(sciname)) { + for (i in seq_along(sci)) { direct <- FALSE - mssg(messages, "\nRetrieving data for taxon '", sciname[i], "'\n") - tmp <- tp_search(name = sciname[i], key = key, ...) + mssg(messages, "\nRetrieving data for taxon '", sci[i], "'\n") + tmp <- tp_search(sci = sci[i], key = key, ...) mm <- NROW(tmp) > 1 if ( @@ -171,7 +173,7 @@ get_tpsid <- function(sciname, ask = TRUE, messages = TRUE, key = NULL, # more than one, try for direct match if (length(id) > 1) { - matchtmp <- df[tolower(df$name) %in% tolower(sciname[i]), "tpsid"] + matchtmp <- df[tolower(df$name) %in% tolower(sci[i]), "tpsid"] if (length(matchtmp) == 1) { id <- matchtmp direct <- TRUE @@ -184,7 +186,7 @@ get_tpsid <- function(sciname, ask = TRUE, messages = TRUE, key = NULL, # prompt rownames(df) <- 1:nrow(df) message("\n\n") - message("\nMore than one tpsid found for taxon '", sciname[i], "'!\n + message("\nMore than one tpsid found for taxon '", sci[i], "'!\n Enter rownumber of taxon (other inputs will return 'NA'):\n") rownames(df) <- 1:nrow(df) print(df) @@ -206,7 +208,7 @@ get_tpsid <- function(sciname, ask = TRUE, messages = TRUE, key = NULL, } } else { if (length(id) != 1) { - warning(sprintf(m_more_than_one_found, "tpsid", sciname[i]), + warning(sprintf(m_more_than_one_found, "tpsid", sci[i]), call. = FALSE) id <- NA_character_ att <- m_na_ask_false @@ -215,9 +217,9 @@ get_tpsid <- function(sciname, ask = TRUE, messages = TRUE, key = NULL, } } res <- list(id = as.character(id), att = att, multiple = mm, direct = direct) - prog$completed(sciname[i], att) + prog$completed(sci[i], att) prog$prog(att) - tstate$add(sciname[i], res) + tstate$add(sci[i], res) } out <- tstate$get() ids <- structure(as.character(unlist(pluck(out, "id"))), class = "tpsid", @@ -278,12 +280,16 @@ check_tpsid <- function(x){ #' @export #' @rdname get_tpsid -get_tpsid_ <- function(sciname, messages = TRUE, key = NULL, rows = NA, ...){ - setNames(lapply(sciname, get_tpsid_help, messages = messages, key=key, rows = rows, ...), sciname) +get_tpsid_ <- function(sci, messages = TRUE, key = NULL, rows = NA, + sciname = NULL, ...) { + + pchk(sciname, "sci") + stats::setNames(lapply(sci, get_tpsid_help, messages = messages, key=key, + rows = rows, ...), sci) } -get_tpsid_help <- function(sciname, messages, key, rows, ...){ - mssg(messages, "\nRetrieving data for taxon '", sciname, "'\n") - df <- tp_search(name=sciname, key=key, ...) +get_tpsid_help <- function(sci, messages, key, rows, ...){ + mssg(messages, "\nRetrieving data for taxon '", sci, "'\n") + df <- tp_search(sci=sci, key=key, ...) if("error" %in% names(df)) NULL else sub_rows(df, rows) } diff --git a/R/get_tsn.R b/R/get_tsn.R index 9078b4f1..2a4fec85 100644 --- a/R/get_tsn.R +++ b/R/get_tsn.R @@ -3,7 +3,7 @@ #' Retrieve the taxonomic serial numbers (TSN) of a taxon from ITIS. #' #' @export -#' @param searchterm character; A vector of common or scientific names. +#' @param sci_com character; A vector of common or scientific names. #' Or, a `taxon_state` object (see [taxon-state]) #' @param searchtype character; One of 'scientific' or 'common', or any #' unique abbreviation @@ -20,6 +20,7 @@ #' [get_tsn_()] to get back all, or a subset, of the raw #' data that you are presented during the ask process. #' @param x Input to as.tsn +#' @param searchterm Deprecated, see `sci_com` #' @param ... Ignored #' @param check logical; Check if ID matches any existing on the DB, only #' used in [as.tsn()] @@ -46,7 +47,7 @@ #' get_tsn(c("Chironomus riparius", "howdy")) #' #' # Using common names -#' get_tsn(searchterm="black bear", searchtype="common") +#' get_tsn("black bear", searchtype="common") #' #' # Convert a tsn without class information to a tsn class #' as.tsn(get_tsn("Quercus douglasii")) # already a tsn, returns the same @@ -73,24 +74,25 @@ #' get_tsn_(c("asdfadfasd","Pinus contorta"), rows=1:5) #' } -get_tsn <- function(searchterm, searchtype = "scientific", accepted = FALSE, - ask = TRUE, messages = TRUE, rows = NA, ...) { +get_tsn <- function(sci_com, searchtype = "scientific", accepted = FALSE, + ask = TRUE, messages = TRUE, rows = NA, searchterm = NULL, ...) { - assert(searchterm, c("character", "taxon_state")) + assert(sci_com, c("character", "taxon_state")) assert(ask, "logical") assert(messages, "logical") assert(searchtype, "character") assert(accepted, "logical") assert_rows(rows) + pchk(searchterm, "sci_com") - if (inherits(searchterm, "character")) { - tstate <- taxon_state$new(class = "tsn", names = searchterm) - items <- searchterm + if (inherits(sci_com, "character")) { + tstate <- taxon_state$new(class = "tsn", names = sci_com) + items <- sci_com } else { - assert_state(searchterm, "tsn") - tstate <- searchterm - searchterm <- tstate$taxa_remaining() - items <- c(searchterm, tstate$taxa_completed()) + assert_state(sci_com, "tsn") + tstate <- sci_com + sci_com <- tstate$taxa_remaining() + items <- c(sci_com, tstate$taxa_completed()) } prog <- progressor$new(items = items, suppress = !messages) @@ -98,12 +100,12 @@ get_tsn <- function(searchterm, searchtype = "scientific", accepted = FALSE, for (i in seq_along(done)) prog$completed(names(done)[i], done[[i]]$att) prog$prog_start() - for (i in seq_along(searchterm)) { + for (i in seq_along(sci_com)) { direct <- FALSE - mssg(messages, "\nRetrieving data for taxon '", searchterm[i], "'\n") + mssg(messages, "\nRetrieving data for taxon '", sci_com[i], "'\n") searchtype <- match.arg(searchtype, c("scientific", "common")) - tsn_df <- ritis::terms(searchterm[i], what = searchtype, ...) + tsn_df <- ritis::terms(sci_com[i], what = searchtype, ...) mm <- NROW(tsn_df) > 1 if (!inherits(tsn_df, "tbl_df") || NROW(tsn_df) == 0) { @@ -140,7 +142,7 @@ get_tsn <- function(searchterm, searchtype = "scientific", accepted = FALSE, if (NROW(tsn_df) > 1) { tsn_df <- data.frame(tsn_df, stringsAsFactors = FALSE) names(tsn_df)[grep(searchtype, names(tsn_df))] <- "target" - matchtmp <- tsn_df[tolower(tsn_df$target) %in% tolower(searchterm[i]), "tsn"] + matchtmp <- tsn_df[tolower(tsn_df$target) %in% tolower(sci_com[i]), "tsn"] if (length(matchtmp) == 1) { tsn <- matchtmp direct <- TRUE @@ -167,7 +169,7 @@ get_tsn <- function(searchterm, searchtype = "scientific", accepted = FALSE, # prompt message("\n\n") print(tsn_df) - message("\nMore than one TSN found for taxon '", searchterm[i], "'!\n + message("\nMore than one TSN found for taxon '", sci_com[i], "'!\n Enter rownumber of taxon (other inputs will return 'NA'):\n") take <- scan(n = 1, quiet = TRUE, what = "raw") @@ -188,7 +190,7 @@ get_tsn <- function(searchterm, searchtype = "scientific", accepted = FALSE, } } else { if (length(tsn) != 1) { - warning(sprintf(m_more_than_one_found, "tsn", searchterm[i]), + warning(sprintf(m_more_than_one_found, "tsn", sci_com[i]), call. = FALSE) tsn <- NA_character_ att <- m_na_ask_false @@ -200,9 +202,9 @@ get_tsn <- function(searchterm, searchtype = "scientific", accepted = FALSE, res <- list(id = as.character(tsn), att = att, multiple = mm, direct = direct) - prog$completed(searchterm[i], att) + prog$completed(sci_com[i], att) prog$prog(att) - tstate$add(searchterm[i], res) + tstate$add(sci_com[i], res) } out <- tstate$get() ids <- structure(as.character(unlist(pluck(out, "id"))), class = "tsn", @@ -265,21 +267,22 @@ check_tsn <- function(x){ #' @export #' @rdname get_tsn -get_tsn_ <- function(searchterm, messages = TRUE, searchtype = "scientific", - accepted = TRUE, rows = NA, ...) { +get_tsn_ <- function(sci_com, messages = TRUE, searchtype = "scientific", + accepted = TRUE, rows = NA, searchterm = NULL, ...) { + pchk(searchterm, "sci_com") stats::setNames( - lapply(searchterm, get_tsn_help, messages = messages, + lapply(sci_com, get_tsn_help, messages = messages, searchtype = searchtype, accepted = accepted, rows = rows, ...), - searchterm + sci_com ) } -get_tsn_help <- function(searchterm, messages, searchtype, accepted, +get_tsn_help <- function(sci_com, messages, searchtype, accepted, rows, ...) { - mssg(messages, "\nRetrieving data for taxon '", searchterm, "'\n") + mssg(messages, "\nRetrieving data for taxon '", sci_com, "'\n") searchtype <- match.arg(searchtype, c("scientific", "common")) - df <- ritis::terms(searchterm, what = searchtype, ...) + df <- ritis::terms(sci_com, what = searchtype, ...) if (!inherits(df, "tbl_df") || NROW(df) == 0) { NULL } else { diff --git a/R/get_uid.R b/R/get_uid.R index bff65b9f..4a5e55f5 100644 --- a/R/get_uid.R +++ b/R/get_uid.R @@ -3,7 +3,7 @@ #' Retrieve the Unique Identifier (UID) of a taxon from NCBI taxonomy browser. #' #' @export -#' @param sciname character; scientific name. Or, a `taxon_state` +#' @param sci_com character; scientific or common name. Or, a `taxon_state` #' object (see [taxon-state]) #' @param ask logical; should get_uid be run in interactive mode? If TRUE and #' more than one TSN is found for the species, the user is asked for input. If @@ -15,7 +15,7 @@ #' class object with one to many identifiers. See [get_uid_()] to get back #' all, or a subset, of the raw data that you are presented during the ask #' process. -#' @param modifier (character) A modifier to the `sciname` given. Options +#' @param modifier (character) A modifier to the `sci_com` given. Options #' include: Organism, Scientific Name, Common Name, All Names, Division, #' Filter, Lineage, GC, MGC, Name Tokens, Next Level, PGC, Properties, Rank, #' Subtree, Synonym, Text Word. These are not checked, so make sure they are @@ -32,6 +32,7 @@ #' itself for options. Optional. See `Filtering` below. #' @param key (character) NCBI Entrez API key. optional. See Details. #' @param x Input to [as.uid()] +#' @param sciname Deprecated, see `sci_com` #' @param ... Ignored #' @param check logical; Check if ID matches any existing on the DB, only used #' in [as.uid()] @@ -85,12 +86,12 @@ #' # Narrow down results to a division or rank, or both #' ## By modifying the query #' ### w/ modifiers to the name -#' get_uid(sciname = "Aratinga acuticauda", modifier = "Organism") -#' get_uid(sciname = "bear", modifier = "Common Name") +#' get_uid(sci_com = "Aratinga acuticauda", modifier = "Organism") +#' get_uid(sci_com = "bear", modifier = "Common Name") #' #' ### w/ rank query -#' get_uid(sciname = "Pinus", rank_query = "genus") -#' get_uid(sciname = "Pinus", rank_query = "subgenus") +#' get_uid(sci_com = "Pinus", rank_query = "genus") +#' get_uid(sci_com = "Pinus", rank_query = "subgenus") #' ### division query doesn't really work, for unknown reasons, so not available #' #' ## By filtering the result @@ -98,20 +99,20 @@ #' ### Results w/o narrowing #' get_uid("Echinacea") #' ### w/ division -#' get_uid(sciname = "Echinacea", division_filter = "eudicots") -#' get_uid(sciname = "Echinacea", division_filter = "sea urchins") +#' get_uid(sci_com = "Echinacea", division_filter = "eudicots") +#' get_uid(sci_com = "Echinacea", division_filter = "sea urchins") #' #' ## Satyrium example #' ### Results w/o narrowing -#' get_uid(sciname = "Satyrium") +#' get_uid(sci_com = "Satyrium") #' ### w/ division -#' get_uid(sciname = "Satyrium", division_filter = "monocots") -#' get_uid(sciname = "Satyrium", division_filter = "butterflies") +#' get_uid(sci_com = "Satyrium", division_filter = "monocots") +#' get_uid(sci_com = "Satyrium", division_filter = "butterflies") #' #' ## Rank example -#' get_uid(sciname = "Pinus") -#' get_uid(sciname = "Pinus", rank_filter = "genus") -#' get_uid(sciname = "Pinus", rank_filter = "subgenus") +#' get_uid(sci_com = "Pinus") +#' get_uid(sci_com = "Pinus", rank_filter = "genus") +#' get_uid(sci_com = "Pinus", rank_filter = "subgenus") #' #' # Fuzzy filter on any filtering fields #' ## uses grep on the inside @@ -155,12 +156,12 @@ #' get_uid("Quercus douglasii", verbose = TRUE) #' } -get_uid <- function(sciname, ask = TRUE, messages = TRUE, rows = NA, +get_uid <- function(sci_com, ask = TRUE, messages = TRUE, rows = NA, modifier = NULL, rank_query = NULL, division_filter = NULL, rank_filter = NULL, - key = NULL, ...) { + key = NULL, sciname = NULL, ...) { - assert(sciname, c("character", "taxon_state")) + assert(sci_com, c("character", "taxon_state")) assert(ask, "logical") assert(messages, "logical") assert(modifier, "character") @@ -169,15 +170,16 @@ get_uid <- function(sciname, ask = TRUE, messages = TRUE, rows = NA, assert(rank_filter, "character") assert_rows(rows) key <- getkey(key, service = "entrez") + pchk(sciname, "sci_com") - if (inherits(sciname, "character")) { - tstate <- taxon_state$new(class = "uid", names = sciname) - items <- sciname + if (inherits(sci_com, "character")) { + tstate <- taxon_state$new(class = "uid", names = sci_com) + items <- sci_com } else { - assert_state(sciname, "uid") - tstate <- sciname - sciname <- tstate$taxa_remaining() - items <- c(sciname, tstate$taxa_completed()) + assert_state(sci_com, "uid") + tstate <- sci_com + sci_com <- tstate$taxa_remaining() + items <- c(sci_com, tstate$taxa_completed()) } prog <- progressor$new(items = items, suppress = !messages) @@ -185,13 +187,13 @@ get_uid <- function(sciname, ask = TRUE, messages = TRUE, rows = NA, for (i in seq_along(done)) prog$completed(names(done)[i], done[[i]]$att) prog$prog_start() - for (i in seq_along(sciname)) { + for (i in seq_along(sci_com)) { direct <- FALSE - mssg(messages, "\nRetrieving data for taxon '", sciname[i], "'\n") - sciname[i] <- gsub(" ", "+", sciname[i]) + mssg(messages, "\nRetrieving data for taxon '", sci_com[i], "'\n") + sci_com[i] <- gsub(" ", "+", sci_com[i]) if (!is.null(modifier)) - sciname[i] <- paste0(sciname[i], sprintf("[%s]", modifier)) - term <- sciname[i] + sci_com[i] <- paste0(sci_com[i], sprintf("[%s]", modifier)) + term <- sci_com[i] if (!is.null(rank_query)) term <- paste0(term, sprintf(" AND %s[Rank]", rank_query)) try_again_errors <- c("Could not resolve host: eutils.ncbi.nlm.nih.gov") @@ -249,7 +251,7 @@ get_uid <- function(sciname, ask = TRUE, messages = TRUE, rows = NA, # check for exact match matchtmp <- df[ tolower( - as.character(df$scientificname)) %in% tolower(sciname[i]), "uid"] + as.character(df$scientificname)) %in% tolower(sci_com[i]), "uid"] if (length(matchtmp) == 1) { uid <- as.character(matchtmp) direct <- TRUE @@ -262,7 +264,7 @@ get_uid <- function(sciname, ask = TRUE, messages = TRUE, rows = NA, att <- "found" } else { warning( - sprintf(m_more_than_one_found, "UID", sciname[i]), + sprintf(m_more_than_one_found, "UID", sci_com[i]), call. = FALSE ) uid <- NA_character_ @@ -272,7 +274,7 @@ get_uid <- function(sciname, ask = TRUE, messages = TRUE, rows = NA, # prompt rownames(df) <- 1:nrow(df) message("\n\n") - message("\nMore than one UID found for taxon '", sciname[i], "'!\n + message("\nMore than one UID found for taxon '", sci_com[i], "'!\n Enter rownumber of taxon (other inputs will return 'NA'):\n") print(df) take <- scan(n = 1, quiet = TRUE, what = 'raw') @@ -297,9 +299,9 @@ get_uid <- function(sciname, ask = TRUE, messages = TRUE, rows = NA, } res <- list(id = as.character(uid), att = att, multiple = mm, direct = direct) - prog$completed(sciname[i], att) + prog$completed(sci_com[i], att) prog$prog(att) - tstate$add(sciname[i], res) + tstate$add(sci_com[i], res) } out <- tstate$get() ids <- structure(pluck_un(out, "id", ""), class = "uid", @@ -395,20 +397,23 @@ check_uid <- function(x){ #' @export #' @rdname get_uid -get_uid_ <- function(sciname, messages = TRUE, rows = NA, key = NULL, ...){ +get_uid_ <- function(sci_com, messages = TRUE, rows = NA, key = NULL, + sciname = NULL, ...) { + key <- getkey(key, "ENTREZ_KEY") - stats::setNames(lapply(sciname, get_uid_help, messages = messages, - rows = rows, key = key, ...), sciname) + pchk(sciname, "sci_com") + stats::setNames(lapply(sci_com, get_uid_help, messages = messages, + rows = rows, key = key, ...), sci_com) } -get_uid_help <- function(sciname, messages, rows, key, ...) { - mssg(messages, "\nRetrieving data for taxon '", sciname, "'\n") +get_uid_help <- function(sci_com, messages, rows, key, ...) { + mssg(messages, "\nRetrieving data for taxon '", sci_com, "'\n") cli <- crul::HttpClient$new(url = ncbi_base(), headers = tx_ual, opts = list(http_version = 2L, ...)) res <- cli$get( "entrez/eutils/esearch.fcgi", query = tc(list(api_key = key, - db = "taxonomy", term = gsub(" ", "+", sciname)))) + db = "taxonomy", term = gsub(" ", "+", sci_com)))) res$raise_for_status() xml_result <- xml2::read_xml(res$parse("UTF-8")) Sys.sleep(0.33) diff --git a/R/get_wiki.R b/R/get_wiki.R index b441497c..9dc4eb05 100644 --- a/R/get_wiki.R +++ b/R/get_wiki.R @@ -1,7 +1,7 @@ #' Get the page name for a Wiki taxon #' #' @export -#' @param x (character) A vector of common or scientific names. Or, a +#' @param sci_com (character) A vector of common or scientific names. Or, a #' `taxon_state` object (see [taxon-state]) #' @param wiki_site (character) Wiki site. One of species (default), pedia, #' commons @@ -16,6 +16,8 @@ #' all, or a subset, of the raw data that you are presented during the ask #' process. #' @param limit (integer) number of records to return +#' @param x For `get_wiki()`: deprecated, see `sci_com`. For `as.wiki`, various, +#' see examples #' @param ... Ignored #' @param check logical; Check if ID matches any existing on the DB, only #' used in [as.wiki()] @@ -28,10 +30,10 @@ #' @seealso [classification()] #' #' @examples \dontrun{ -#' get_wiki(x = "Quercus douglasii") -#' get_wiki(x = "Quercu") -#' get_wiki(x = "Quercu", "pedia") -#' get_wiki(x = "Quercu", "commons") +#' get_wiki(sci_com = "Quercus douglasii") +#' get_wiki(sci_com = "Quercu") +#' get_wiki(sci_com = "Quercu", "pedia") +#' get_wiki(sci_com = "Quercu", "commons") #' #' # diff. wikis with wikipedia #' get_wiki("Malus domestica", "pedia") @@ -45,24 +47,25 @@ #' as.wiki("Malus_domestica", wiki_site = "pedia", wiki = "da") #' } -get_wiki <- function(x, wiki_site = "species", wiki = "en", ask = TRUE, - messages = TRUE, limit = 100, rows = NA, ...) { +get_wiki <- function(sci_com, wiki_site = "species", wiki = "en", ask = TRUE, + messages = TRUE, limit = 100, rows = NA, x = NULL, ...) { - assert(x, c("character", "taxon_state")) + assert(sci_com, c("character", "taxon_state")) assert(ask, "logical") assert(wiki_site, "character") assert(wiki, "character") assert(messages, "logical") assert_rows(rows) + pchk(x, "sci_com") - if (inherits(x, "character")) { - tstate <- taxon_state$new(class = "wiki", names = x) - items <- x + if (inherits(sci_com, "character")) { + tstate <- taxon_state$new(class = "wiki", names = sci_com) + items <- sci_com } else { - assert_state(x, "wiki") - tstate <- x - x <- tstate$taxa_remaining() - items <- c(x, tstate$taxa_completed()) + assert_state(sci_com, "wiki") + tstate <- sci_com + sci_com <- tstate$taxa_remaining() + items <- c(sci_com, tstate$taxa_completed()) } prog <- progressor$new(items = items, suppress = !messages) @@ -70,15 +73,15 @@ get_wiki <- function(x, wiki_site = "species", wiki = "en", ask = TRUE, for (i in seq_along(done)) prog$completed(names(done)[i], done[[i]]$att) prog$prog_start() - for (i in seq_along(x)) { + for (i in seq_along(sci_com)) { direct <- FALSE - mssg(messages, "\nRetrieving data for taxon '", x, "'\n") + mssg(messages, "\nRetrieving data for taxon '", sci_com[i], "'\n") df <- switch( wiki_site, - species = wikitaxa::wt_wikispecies_search(query = x[i], limit = limit, ...), - pedia = wikitaxa::wt_wikipedia_search(query = x[i], wiki = wiki, + species = wikitaxa::wt_wikispecies_search(query = sci_com[i], limit = limit, ...), + pedia = wikitaxa::wt_wikipedia_search(query = sci_com[i], wiki = wiki, limit = limit, ...), - commons = wikitaxa::wt_wikicommons_search(query = x[i], limit = limit, ...) + commons = wikitaxa::wt_wikicommons_search(query = sci_com[i], limit = limit, ...) )$query$search mm <- NROW(df) > 1 @@ -107,7 +110,7 @@ get_wiki <- function(x, wiki_site = "species", wiki = "en", ask = TRUE, # check for direct match if (NROW(df) > 1) { df <- data.frame(df, stringsAsFactors = FALSE) - matchtmp <- df[tolower(df$title) %in% tolower(x[i]), "title"] + matchtmp <- df[tolower(df$title) %in% tolower(sci_com[i]), "title"] if (length(matchtmp) == 1) { id <- matchtmp direct <- TRUE @@ -133,7 +136,7 @@ get_wiki <- function(x, wiki_site = "species", wiki = "en", ask = TRUE, # prompt message("\n\n") print(df) - message("\nMore than one wiki ID found for taxon '", x[i], "'!\n + message("\nMore than one wiki ID found for taxon '", sci_com[i], "'!\n Enter rownumber of taxon (other inputs will return 'NA'):\n") take <- scan(n = 1, quiet = TRUE, what = 'raw') @@ -166,9 +169,9 @@ get_wiki <- function(x, wiki_site = "species", wiki = "en", ask = TRUE, res <- list(id = as.character(id), att = att, multiple = mm, direct = direct) - prog$completed(x[i], att) + prog$completed(sci_com[i], att) prog$prog(att) - tstate$add(x[i], res) + tstate$add(sci_com[i], res) } out <- tstate$get() ids <- structure(pluck_un(out, "id", ""), class = "wiki", diff --git a/R/get_wormsid.R b/R/get_wormsid.R index 48f385bc..ab3ce71a 100644 --- a/R/get_wormsid.R +++ b/R/get_wormsid.R @@ -4,7 +4,7 @@ #' Species (WORMS). #' #' @export -#' @param query character; A vector of common or scientific names. Or, a +#' @param sci_com character; A vector of common or scientific names. Or, a #' `taxon_state` object (see [taxon-state]) #' @param searchtype character; One of 'scientific' or 'common', or any unique #' abbreviation @@ -27,7 +27,8 @@ #' class object with one to many identifiers. See [get_wormsid_()] to get back #' all, or a subset, of the raw data that you are presented during the ask #' process. -#' @param x Input to as.wormsid +#' @param query Deprecated, see `sci_com` +#' @param x Input to `as.wormsid` #' @param ... Ignored #' @param check logical; Check if ID matches any existing on the DB, only #' used in [as.wormsid()] @@ -104,11 +105,11 @@ #' get_wormsid_("Plat", rows=1:75) #' # get_wormsid_(c("asdfadfasd","Plat"), rows=1:5) #' } -get_wormsid <- function(query, searchtype = "scientific", marine_only = TRUE, +get_wormsid <- function(sci_com, searchtype = "scientific", marine_only = TRUE, fuzzy = NULL, accepted = FALSE, ask = TRUE, messages = TRUE, - rows = NA, ...) { + rows = NA, query = NULL, ...) { - assert(query, c("character", "taxon_state")) + assert(sci_com, c("character", "taxon_state")) assert(searchtype, "character") assert(marine_only, "logical") assert(fuzzy, "logical") @@ -116,15 +117,16 @@ get_wormsid <- function(query, searchtype = "scientific", marine_only = TRUE, assert(ask, "logical") assert(messages, "logical") assert_rows(rows) + pchk(query, "sci_com") - if (inherits(query, "character")) { - tstate <- taxon_state$new(class = "wormsid", names = query) - items <- query + if (inherits(sci_com, "character")) { + tstate <- taxon_state$new(class = "wormsid", names = sci_com) + items <- sci_com } else { - assert_state(query, "wormsid") - tstate <- query - query <- tstate$taxa_remaining() - items <- c(query, tstate$taxa_completed()) + assert_state(sci_com, "wormsid") + tstate <- sci_com + sci_com <- tstate$taxa_remaining() + items <- c(sci_com, tstate$taxa_completed()) } prog <- progressor$new(items = items, suppress = !messages) @@ -132,18 +134,18 @@ get_wormsid <- function(query, searchtype = "scientific", marine_only = TRUE, for (i in seq_along(done)) prog$completed(names(done)[i], done[[i]]$att) prog$prog_start() - for (i in seq_along(query)) { + for (i in seq_along(sci_com)) { direct <- FALSE - mssg(messages, "\nRetrieving data for taxon '", query[i], "'\n") + mssg(messages, "\nRetrieving data for taxon '", sci_com[i], "'\n") if (!searchtype %in% c("scientific", "common")) { stop("'searchtype' must be one of 'scientific' or 'common'", call. = FALSE) } wmdf <- switch( searchtype, - scientific = worms_worker(query[i], worrms::wm_records_name, rows, + scientific = worms_worker(sci_com[i], worrms::wm_records_name, rows, marine_only, fuzzy %||% TRUE, ...), - common = worms_worker(query[i], worrms::wm_records_common, rows, + common = worms_worker(sci_com[i], worrms::wm_records_common, rows, marine_only, fuzzy %||% FALSE, ...) ) mm <- NROW(wmdf) > 1 @@ -178,7 +180,7 @@ get_wormsid <- function(query, searchtype = "scientific", marine_only = TRUE, # check for direct match if (nrow(wmdf) > 1) { names(wmdf)[grep("scientificname", names(wmdf))] <- "target" - matchtmp <- wmdf[tolower(wmdf$target) %in% tolower(query[i]), "id"] + matchtmp <- wmdf[tolower(wmdf$target) %in% tolower(sci_com[i]), "id"] if (length(matchtmp) == 1) { wmid <- matchtmp direct <- TRUE @@ -203,7 +205,7 @@ get_wormsid <- function(query, searchtype = "scientific", marine_only = TRUE, # prompt message("\n\n") print(wmdf) - message("\nMore than one WORMS ID found for taxon '", query[i], "'!\n + message("\nMore than one WORMS ID found for taxon '", sci_com[i], "'!\n Enter rownumber of taxon (other inputs will return 'NA'):\n") # prompt take <- scan(n = 1, quiet = TRUE, what = 'raw') @@ -223,7 +225,7 @@ get_wormsid <- function(query, searchtype = "scientific", marine_only = TRUE, } } else { if (length(wmid) != 1) { - warning(sprintf(m_more_than_one_found, "Worms ID", query[i]), + warning(sprintf(m_more_than_one_found, "Worms ID", sci_com[i]), call. = FALSE) wmid <- NA_character_ att <- m_na_ask_false @@ -234,9 +236,9 @@ get_wormsid <- function(query, searchtype = "scientific", marine_only = TRUE, } res <- list(id = as.character(wmid), att = att, multiple = mm, direct = direct) - prog$completed(query[i], att) + prog$completed(sci_com[i], att) prog$prog(att) - tstate$add(query[i], res) + tstate$add(sci_com[i], res) } out <- tstate$get() ids <- structure(pluck_un(out, "id", ""), class = "wormsid", @@ -310,14 +312,16 @@ check_wormsid <- function(x){ #' @export #' @rdname get_wormsid -get_wormsid_ <- function(query, messages = TRUE, searchtype = "scientific", - marine_only = TRUE, fuzzy = NULL, accepted = TRUE, rows = NA, ...) { +get_wormsid_ <- function(sci_com, messages = TRUE, searchtype = "scientific", + marine_only = TRUE, fuzzy = NULL, accepted = TRUE, rows = NA, query = NULL, + ...) { + pchk(query, "sci_com") stats::setNames( - lapply(query, get_wormsid_help, messages = messages, + lapply(sci_com, get_wormsid_help, messages = messages, searchtype = searchtype, marine_only = marine_only, fuzzy = fuzzy, accepted = accepted, rows = rows, ...), - query + sci_com ) } diff --git a/R/gni_search.R b/R/gni_search.R index a0f7a19b..f2a89315 100644 --- a/R/gni_search.R +++ b/R/gni_search.R @@ -3,30 +3,32 @@ #' @description Uses the Global Names Index, see http://gni.globalnames.org #' #' @export -#' @param search_term Name pattern you want to search for. WARNING: Does -#' not work for vernacular/common names. Search term may include following -#' options (Note: can, uni, gen, sp, ssp, au, yr work only for parsed names +#' @param sci (character) required. Name pattern you want to search +#' for. WARNING: Does not work for common names. Search term may include +#' following options (Note: can, uni, gen, sp, ssp, au, yr work only for +#' parsed names) #' -#' * * wild card - Search by part of a word (E.g.: planta*) -#' * exact exact match - Search for exact match of a literal string +#' * `*` wild card - Search by part of a word (E.g.: planta*) +#' * `exact` exact match - Search for exact match of a literal string #' (E.g.: exact:Parus major) -#' * ns name string- Search for literal string from its beginning (other +#' * `ns` name string- Search for literal string from its beginning (other #' modifiers will be ignored) (E.g.: ns:parus maj*) -#' * can canonical form- Search name without authors (other modifiers will +#' * `can` canonical form- Search name without authors (other modifiers will #' be ignored) (E.g.: can:parus major) -#' * uni uninomial- Search for higher taxa (E.g.: uni:parus) -#' * gen genus - Search by genus epithet of species name (E.g.: gen:parus) -#' * sp species - Search by species epithet (E.g.: sp:major) -#' * ssp subspecies - Search by infraspecies epithet (E.g.: ssp:major) -#' * au author - Search by author word (E.g.: au:Shipunov) -#' * yr year - Search by year (E.g.: yr:2005) +#' * `uni` uninomial- Search for higher taxa (E.g.: uni:parus) +#' * `gen` genus - Search by genus epithet of species name (E.g.: gen:parus) +#' * `sp` species - Search by species epithet (E.g.: sp:major) +#' * `ssp` subspecies - Search by infraspecies epithet (E.g.: ssp:major) +#' * `au` author - Search by author word (E.g.: au:Shipunov) +#' * `yr` year - Search by year (E.g.: yr:2005) #' #' @param per_page Number of items per one page (numbers larger -#' than 1000 will be decreased to 1000) (default is 30). +#' than 1000 will be decreased to 1000) (default is 30). #' @param page Page number you want to see (default is 1). #' @param justtotal Return only the total results found. #' @param parse_names If `TRUE`, use [gni_parse()] to parse #' names. Default: `FALSE` +#' @param search_term Deprecated, see `sci` #' @param ... Curl options passed on to [crul::verb-GET] #' @author Scott Chamberlain \email{myrmecocystus@@gmail.com} #' @return data.frame of results. @@ -37,20 +39,21 @@ #' @details Note that you can use fuzzy searching, e.g., by attaching an #' asterisk to the end of a search term. See the first two examples below #' @examples \dontrun{ -#' gni_search(search_term = "ani*") -#' gni_search(search_term = "ama*", per_page = 3, page = 21) -#' gni_search(search_term = "animalia", per_page = 8, page = 1) -#' gni_search(search_term = "animalia", per_page = 8, page = 1, justtotal=TRUE) +#' gni_search(sci = "ani*") +#' gni_search(sci = "ama*", per_page = 3, page = 21) +#' gni_search(sci = "animalia", per_page = 8, page = 1) +#' gni_search(sci = "animalia", per_page = 8, page = 1, justtotal=TRUE) #' -#' gni_search(search_term = "Cyanistes caeruleus", parse_names=TRUE) +#' gni_search(sci = "Cyanistes caeruleus", parse_names=TRUE) #' #' # pass on curl options -#' gni_search(search_term = "ani*", verbose = TRUE) +#' gni_search(sci = "ani*", verbose = TRUE) #' } -gni_search <- function(search_term = NULL, per_page = NULL, page = NULL, - justtotal = FALSE, parse_names = FALSE, ...) { +gni_search <- function(sci, per_page = NULL, page = NULL, + justtotal = FALSE, parse_names = FALSE, search_term = NULL, ...) { - query <- tc(list(search_term = search_term, per_page = per_page, + pchk(search_term, "sci") + query <- tc(list(search_term = sci, per_page = per_page, page = page)) cli <- crul::HttpClient$new(paste0(gni_base(), "name_strings.json"), headers = tx_ual, opts = list(...)) diff --git a/R/nbn_search.R b/R/nbn_search.R index 51f4b18f..dbb650b7 100644 --- a/R/nbn_search.R +++ b/R/nbn_search.R @@ -1,7 +1,7 @@ #' Search UK National Biodiversity Network #' #' @export -#' @param q (character) The query terms(s) +#' @param sci_com (character) The query terms(s), a scientific or common name #' @param fq (character) Filters to be applied to the original query. These #' are additional params of the form fq=INDEXEDFIELD:VALUE e.g. #' fq=rank:kingdom. See for all @@ -12,6 +12,7 @@ #' @param order (character) Supports "asc" or "desc" #' @param facets (list) Comma separated list of the fields to create facets #' on e.g. facets=basis_of_record. +#' @param q Deprecated, see `sci` #' @param ... Further args passed on to [crul::HttpClient]. #' @family nbn #' @return a list with slots for metadata (`meta`) with list of response @@ -20,23 +21,24 @@ #' @references #' #' @examples \dontrun{ -#' x <- nbn_search(q = "Vulpes") +#' x <- nbn_search(sci_com = "Vulpes") #' x$meta$totalRecords #' x$meta$pageSize #' x$meta$urlParameters #' x$meta$queryTitle #' head(x$data) #' -#' nbn_search(q = "blackbird", start = 4) +#' nbn_search(sci_com = "blackbird", start = 4) #' #' # debug curl stuff -#' nbn_search(q = "blackbird", verbose = TRUE) +#' nbn_search(sci_com = "blackbird", verbose = TRUE) #' } -nbn_search <- function(q, fq = NULL, order = NULL, sort = NULL, start = 0, - rows = 25, facets = NULL, ...) { +nbn_search <- function(sci_com, fq = NULL, order = NULL, sort = NULL, + start = 0, rows = 25, facets = NULL, q = NULL, ...) { + pchk(q, "sci_com") args <- tc(list( - q = q, fq = fq, pageSize = rows, startIndex = start, sort = sort, + q = sci_com, fq = fq, pageSize = rows, startIndex = start, sort = sort, dir = order, facets = facets )) nbn_GET(file.path(nbn_base(), "search"), args, ...) diff --git a/R/pow_search.R b/R/pow_search.R index 8b3b7082..897a93ee 100644 --- a/R/pow_search.R +++ b/R/pow_search.R @@ -1,11 +1,12 @@ #' Search Kew's Plants of the World #' #' @export -#' @param q (character) query terms +#' @param sci_com (character) query terms, scientific or common name #' @param limit (integer) Number of records to return. default: 100 #' @param cursor (character) cursor string #' @param sort (character) The field to sort by and sort order separted with #' underscore, e.g., `sort="name_desc"` +#' @param q Deprecated, see `sci_com` #' @param ... Further args passed on to [crul::HttpClient]. #' @return a list with slots for metadata (`meta`) with list of response #' attributes, and data (`data`) with a data.frame of results @@ -13,7 +14,7 @@ #' @references #' @family pow #' @examples \dontrun{ -#' x <- pow_search(q = "Quercus") +#' x <- pow_search(sci_com = "Quercus") #' x$meta #' x$meta$totalResults #' x$meta$perPage @@ -23,23 +24,26 @@ #' head(x$data) #' #' # pagination -#' pow_search(q = "sunflower", limit = 2) +#' pow_search(sci_com = "sunflower", limit = 2) #' #' # debug curl stuff -#' invisible(pow_search(q = "Helianthus annuus", verbose = TRUE)) +#' invisible(pow_search(sci_com = "Helianthus annuus", verbose = TRUE)) #' #' # sort -#' desc <- pow_search(q = "Helianthus", sort = "name_desc") +#' desc <- pow_search(sci_com = "Helianthus", sort = "name_desc") #' desc$data$name -#' asc <- pow_search(q = "Helianthus", sort = "name_asc") +#' asc <- pow_search(sci_com = "Helianthus", sort = "name_asc") #' asc$data$name #' } -pow_search <- function(q, limit = 100, cursor = "*", sort = NULL, ...) { - assert(q, "character") +pow_search <- function(sci_com, limit = 100, cursor = "*", sort = NULL, + q = NULL, ...) { + + assert(sci_com, "character") assert(limit, c("integer", "numeric")) assert(cursor, "character") assert(sort, "character") - args <- tc(list(q = q, perPage = limit, cursor = cursor, sort = sort)) + pchk(q, "sci_com") + args <- tc(list(q = sci_com, perPage = limit, cursor = cursor, sort = sort)) pow_GET(file.path(pow_base(), "api/2", "search"), args, ...) } diff --git a/R/taxize-params.R b/R/taxize-params.R new file mode 100644 index 00000000..95747e01 --- /dev/null +++ b/R/taxize-params.R @@ -0,0 +1,20 @@ +#' taxize parameters +#' +#' Information on standardized parameters across the package +#' +#' @name taxize-params +#' @section Standardized parameters: +#' +#' - `sci`: scientific name +#' - `com`: common name +#' - `id`: name identifier +#' - `sci_com`: scientific name or common name +#' - `sci_id`: scientific name or name identifier +#' +#' We were going to standardize parameter names for cases in which +#' a parameter accepts either of three options: scientific name, +#' common name, or name identifier. However, there was no clear +#' parameter name we could use for this case, so we've left +#' parameter names as they are for the two cases ([get_ids()] and +#' [vascan_search()]) +NULL diff --git a/R/tp_search.R b/R/tp_search.R index 1bd8036d..a5054330 100644 --- a/R/tp_search.R +++ b/R/tp_search.R @@ -1,17 +1,19 @@ #' Search Tropicos by scientific name, common name, or Tropicos ID. #' #' @export -#' @param name Your search string. For instance "poa annua". See Details. -#' @param commonname Your search string. For instance "annual blue grass" -#' @param nameid Your search string. For instance "25509881" -#' @param orderby Your search string. For instance "1" -#' @param sortorder Your search string. For instance "ascending" -#' @param pagesize Your search string. For instance "100" -#' @param startrow Your search string. For instance "1" -#' @param type Type of search, "wildcard" (default) will add a wildcard to the end -#' of your search string. "exact" will use your search string exactly. +#' @param sci A scientific name, e.g., "poa annua". See Details. +#' @param com A common name, e.g., "annual blue grass" +#' @param nameid Your search string. e.g., "25509881" +#' @param orderby Your search string. e.g., "1" +#' @param sortorder Your search string. e.g., "ascending" +#' @param pagesize Your search string. e.g., "100" +#' @param startrow Your search string. e.g., "1" +#' @param type Type of search, "wildcard" (default) will add a wildcard to +#' the end of your search string. "exact" will use your search string exactly. #' @param key Your Tropicos API key; See [taxize-authentication] #' for help on authentication +#' @param name Deprecated, see `sci` +#' @param commonname Deprecated, see `com` #' @param ... Further args passed on to [crul::HttpClient] #' @return List or dataframe. #' @references @@ -21,28 +23,35 @@ #' In addition, Tropicos for some reason doesn't want to see sub-specific rank #' names like `var`/`subsp`, so remove those from your query. #' @examples \dontrun{ -#' tp_search(name = 'Poa annua') -#' tp_search(name = 'Poa annua subsp. annua') -#' tp_search(name = 'Poa annua var. annua') -#' tp_search(name = 'Poa annua var annua') -#' tp_search(name = 'Poa annua annua') +#' tp_search(sci = 'Poa annua') +#' tp_search(sci = 'Poa annua subsp. annua') +#' tp_search(sci = 'Poa annua var. annua') +#' tp_search(sci = 'Poa annua var annua') +#' tp_search(sci = 'Poa annua annua') #' } -tp_search <- function(name=NULL, commonname=NULL, nameid=NULL, orderby=NULL, - sortorder=NULL, pagesize=NULL, startrow=NULL, type=NULL, key=NULL, ...) { +tp_search <- function(sci=NULL, com=NULL, nameid=NULL, orderby=NULL, + sortorder=NULL, pagesize=NULL, startrow=NULL, type=NULL, key=NULL, name=NULL, + commonname=NULL, ...) { + pchk(name, "sci") + pchk(commonname, "com") + if (!is.null(name)) sci <- name + if (!is.null(commonname)) com <- commonname url = 'http://services.tropicos.org/Name/Search' key <- getkey(key, "TROPICOS_KEY") - if (!is.null(name)) { - if (grepl(paste(sprintf("\\s%s\\.?\\s", subsp_ranks), collapse = "|"), name)) { - warning("Tropicos doesn't like sub-specific ranks - remove them in your query", call. = FALSE) + if (!is.null(sci)) { + if (grepl(paste(sprintf("\\s%s\\.?\\s", subsp_ranks), collapse = "|"), sci)) { + warning("Tropicos doesn't like sub-specific ranks - remove them in your query", + call. = FALSE) } - if (grepl("\\.", name)) { - warning("'.' detected, being URL encoded prior to data request", call. = FALSE) + if (grepl("\\.", sci)) { + warning("'.' detected, being URL encoded prior to data request", + call. = FALSE) } - name <- gsub("\\.", "%2E", name) + sci <- gsub("\\.", "%2E", sci) } - args <- tc(list(format='json', name=name, nameid=nameid, - commonname=commonname, orderby=orderby, sortorder=sortorder, + args <- tc(list(format='json', name=sci, nameid=nameid, + commonname=com, orderby=orderby, sortorder=sortorder, pagesize=pagesize, startrow=startrow, type=type, apikey=key)) tt <- tp_GET(url, args, raise = FALSE, ...) out <- jsonlite::fromJSON(tt, FALSE) diff --git a/R/zzz.R b/R/zzz.R index f8f648f4..af99bc01 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -280,3 +280,25 @@ ncbi_rate_limit_pause <- function(key) { Sys.sleep(0.101) } } + +# foo <- function(x) { +# deparse(substitute(x)) +# } +# bar <- function(z) { +# foo(z) +# } +# bar(z = "adf") +taxize_ck <- conditionz::ConditionKeeper$new(times = 1, condition = "warning") +pchk <- function(from, to, pkg_version = "v0.9.97") { + assert(from, "character") + assert(to, "character") + assert(pkg_version, "character") + # & will be removed in a future version + param_mssg <- "`%s` param is deprecated as of taxize %s, use `%s` instead." + parms_help <- "\nSee `?taxize-params` for more information." + once_per <- "\nThis warning will be thrown once per R session." + mssg <- c(sprintf(param_mssg, deparse(substitute(from)), pkg_version, to), + parms_help, once_per) + if (!is.null(from)) + taxize_ck$handle_conditions(warning(mssg)) +} diff --git a/man/bold_search.Rd b/man/bold_search.Rd index 59f15bcd..0fdc68bb 100644 --- a/man/bold_search.Rd +++ b/man/bold_search.Rd @@ -5,17 +5,18 @@ \title{Search Barcode of Life for taxonomic IDs} \usage{ bold_search( - name = NULL, + sci = NULL, id = NULL, fuzzy = FALSE, dataTypes = "basic", includeTree = FALSE, response = FALSE, + name = NULL, ... ) } \arguments{ -\item{name}{(character) One or more scientific names.} +\item{sci}{(character) One or more scientific names.} \item{id}{(integer) One or more BOLD taxonomic identifiers.} @@ -33,6 +34,8 @@ passed.} \item{response}{(logical) Note that response is the object that returns from the curl call, useful for debugging, and getting detailed info on the API call.} +\item{name}{Deprecated, see \code{sci}} + \item{...}{named curl options passed on to \link[crul:verb-GET]{crul::verb-GET}} } \value{ @@ -42,8 +45,8 @@ A list of data.frame's. Search Barcode of Life for taxonomic IDs } \details{ -You must provide one of name or id to this function. The other -parameters are optional. Note that when passing in \code{name}, \code{fuzzy} can be used +You must provide one of \code{sci} or \code{id} to this function. The other +parameters are optional. Note that when passing in \code{sci}, \code{fuzzy} can be used as well, while if \code{id} is passed, then \code{fuzzy} is ignored, and \code{dataTypes} \code{includeTree} can be used. @@ -69,18 +72,18 @@ summary, wikipedia URL, GBIF map. \examples{ \dontrun{ # A basic example -bold_search(name="Apis") -bold_search(name="Agapostemon") -bold_search(name="Poa") +bold_search(sci="Apis") +bold_search(sci="Agapostemon") +bold_search(sci="Poa") # Fuzzy search -head(bold_search(name="Po", fuzzy=TRUE)) -head(bold_search(name="Aga", fuzzy=TRUE)) +head(bold_search(sci="Po", fuzzy=TRUE)) +head(bold_search(sci="Aga", fuzzy=TRUE)) # Many names -bold_search(name=c("Apis","Puma concolor")) +bold_search(sci=c("Apis","Puma concolor")) nms <- names_list('species') -bold_search(name=nms) +bold_search(sci=nms) # Searching by ID - dataTypes can be used, and includeTree can be used bold_search(id=88899) diff --git a/man/eol_search.Rd b/man/eol_search.Rd index 51612552..52b1c97d 100644 --- a/man/eol_search.Rd +++ b/man/eol_search.Rd @@ -5,18 +5,19 @@ \title{Search for terms in EOL database.} \usage{ eol_search( - terms, + sci, page = 1, exact = NULL, filter_tid = NULL, filter_heid = NULL, filter_by_string = NULL, cache_ttl = NULL, + terms = NULL, ... ) } \arguments{ -\item{terms}{search terms (character)} +\item{sci}{(character) scientific name} \item{page}{A maximum of 30 results are returned per page. This parameter allows you to fetch more pages of results if there are more than @@ -37,6 +38,8 @@ to filter search results} \item{cache_ttl}{The number of seconds you wish to have the response cached.} +\item{terms}{Deprecated, see \code{sci}} + \item{...}{Curl options passed on to \link[crul:HttpClient]{crul::HttpClient}} } \value{ @@ -60,9 +63,9 @@ this function only returns JSON for now. } \examples{ \dontrun{ -eol_search(terms='Homo') -eol_search(terms='Salix', verbose = TRUE) -eol_search(terms='Ursus americanus') +eol_search(sci='Homo') +eol_search(sci='Salix', verbose = TRUE) +eol_search(sci='Ursus americanus') eol_search('Pinus contorta') } } diff --git a/man/get_boldid.Rd b/man/get_boldid.Rd index 2328fcd6..33c6c429 100644 --- a/man/get_boldid.Rd +++ b/man/get_boldid.Rd @@ -13,7 +13,7 @@ \title{Get the BOLD (Barcode of Life) code for a search term.} \usage{ get_boldid( - searchterm, + sci, fuzzy = FALSE, dataTypes = "basic", includeTree = FALSE, @@ -23,6 +23,7 @@ get_boldid( rank = NULL, division = NULL, parent = NULL, + searchterm = NULL, ... ) @@ -41,17 +42,18 @@ as.boldid(x, check = TRUE) \method{as.data.frame}{boldid}(x, ...) get_boldid_( - searchterm, + sci, messages = TRUE, fuzzy = FALSE, dataTypes = "basic", includeTree = FALSE, rows = NA, + searchterm = NULL, ... ) } \arguments{ -\item{searchterm}{character; A vector of scientific names. Or, +\item{sci}{character; A vector of scientific names. Or, a \code{taxon_state} object (see \link{taxon-state})} \item{fuzzy}{(logical) Whether to use fuzzy search or not (default: FALSE).} @@ -83,6 +85,8 @@ below.} \item{parent}{(character) A parent name (i.e., the parent of the target search taxon). Optional. See \code{Filtering} below.} +\item{searchterm}{Deprecated, see \code{sci}} + \item{...}{Curl options passed on to \code{\link[crul:verb-GET]{crul::verb-GET}}} \item{x}{Input to \code{\link[=as.boldid]{as.boldid()}}} @@ -115,20 +119,20 @@ down to the set that matches your query, and removes the rest. \examples{ \dontrun{ -get_boldid(searchterm = "Agapostemon") -get_boldid(searchterm = "Chironomus riparius") +get_boldid(sci = "Agapostemon") +get_boldid(sci = "Chironomus riparius") get_boldid(c("Chironomus riparius","Quercus douglasii")) splist <- names_list('species') get_boldid(splist, messages=FALSE) # Fuzzy searching -get_boldid(searchterm="Osmi", fuzzy=TRUE) +get_boldid(sci="Osmi", fuzzy=TRUE) # Get back a subset -get_boldid(searchterm="Osmi", fuzzy=TRUE, rows = 1) -get_boldid(searchterm="Osmi", fuzzy=TRUE, rows = 1:10) -get_boldid(searchterm=c("Osmi","Aga"), fuzzy=TRUE, rows = 1) -get_boldid(searchterm=c("Osmi","Aga"), fuzzy=TRUE, rows = 1:3) +get_boldid(sci="Osmi", fuzzy=TRUE, rows = 1) +get_boldid(sci="Osmi", fuzzy=TRUE, rows = 1:10) +get_boldid(sci=c("Osmi","Aga"), fuzzy=TRUE, rows = 1) +get_boldid(sci=c("Osmi","Aga"), fuzzy=TRUE, rows = 1:3) # found get_boldid('Epicordulia princeps') diff --git a/man/get_eolid.Rd b/man/get_eolid.Rd index 0acadc74..f1f4dc47 100644 --- a/man/get_eolid.Rd +++ b/man/get_eolid.Rd @@ -13,12 +13,13 @@ \title{Get the EOL ID from Encyclopedia of Life from taxonomic names.} \usage{ get_eolid( - sciname, + sci_com, ask = TRUE, messages = TRUE, rows = NA, rank = NULL, data_source = NULL, + sciname = NULL, ... ) @@ -36,10 +37,10 @@ as.eolid(x, check = TRUE) \method{as.data.frame}{eolid}(x, ...) -get_eolid_(sciname, messages = TRUE, rows = NA, ...) +get_eolid_(sci_com, messages = TRUE, rows = NA, sciname = NULL, ...) } \arguments{ -\item{sciname}{character; one or more scientific or common names. Or, +\item{sci_com}{character; one or more scientific or common names. Or, a \code{taxon_state} object (see \link{taxon-state})} \item{ask}{logical; should get_eolid be run in interactive mode? @@ -63,6 +64,8 @@ so inspect the data itself for options. Optional. See \code{Filtering} below.} longish names like e.g., "Barcode of Life Data Systems" or "USDA PLANTS images". Optional. See \code{Filtering} below.} +\item{sciname}{Deprecated, see \code{sci_com}} + \item{...}{Further args passed on to \code{\link[=eol_search]{eol_search()}}} \item{x}{Input to \code{\link[=as.eolid]{as.eolid()}}} @@ -112,8 +115,8 @@ removes the rest. \examples{ \dontrun{ -get_eolid(sciname='Pinus contorta') -get_eolid(sciname='Puma concolor') +get_eolid(sci_com='Pinus contorta') +get_eolid(sci_com='Puma concolor') get_eolid(c("Puma concolor", "Pinus contorta")) @@ -124,7 +127,7 @@ get_eolid('Poa annua', rows=2) get_eolid('Poa annua', rows=1:2) # When not found -get_eolid(sciname="uaudnadndj") +get_eolid(sci_com="uaudnadndj") get_eolid(c("Chironomus riparius", "uaudnadndj")) # filter results to a rank or data source, or both diff --git a/man/get_gbifid.Rd b/man/get_gbifid.Rd index a533dc47..4cb0bcf7 100644 --- a/man/get_gbifid.Rd +++ b/man/get_gbifid.Rd @@ -13,7 +13,7 @@ \title{Get the GBIF backbone taxon ID from taxonomic names.} \usage{ get_gbifid( - sciname, + sci, ask = TRUE, messages = TRUE, rows = NA, @@ -23,6 +23,7 @@ get_gbifid( family = NULL, rank = NULL, method = "backbone", + sciname = NULL, ... ) @@ -40,10 +41,16 @@ as.gbifid(x, check = FALSE) \method{as.data.frame}{gbifid}(x, ...) -get_gbifid_(sciname, messages = TRUE, rows = NA, method = "backbone") +get_gbifid_( + sci, + messages = TRUE, + rows = NA, + method = "backbone", + sciname = NULL +) } \arguments{ -\item{sciname}{(character) one or more scientific names. Or, a \code{taxon_state} +\item{sci}{(character) one or more scientific names. Or, a \code{taxon_state} object (see \link{taxon-state})} \item{ask}{logical; should get_gbifid be run in interactive mode? @@ -72,6 +79,8 @@ data itself for options. Optional. See \code{Filtering} below.} \item{method}{(character) one of "backbone" or "lookup". See Details.} +\item{sciname}{Deprecated, see \code{sci}} + \item{...}{Ignored} \item{x}{Input to \code{\link[=as.gbifid]{as.gbifid()}}} @@ -119,9 +128,9 @@ Filtering narrows down to the set that matches your query, and removes the rest. \examples{ \dontrun{ -get_gbifid(sciname='Poa annua') -get_gbifid(sciname='Pinus contorta') -get_gbifid(sciname='Puma concolor') +get_gbifid(sci='Poa annua') +get_gbifid(sci='Pinus contorta') +get_gbifid(sci='Puma concolor') #lots of queries spp <- names_list("species", 10) @@ -134,12 +143,12 @@ xx get_gbifid(c("Poa annua", "Pinus contorta")) # specify rows to limit choices available -get_gbifid(sciname='Pinus') -get_gbifid(sciname='Pinus', rows=10) -get_gbifid(sciname='Pinus', rows=1:3) +get_gbifid(sci='Pinus') +get_gbifid(sci='Pinus', rows=10) +get_gbifid(sci='Pinus', rows=1:3) # When not found, NA given -get_gbifid(sciname="uaudnadndj") +get_gbifid(sci="uaudnadndj") get_gbifid(c("Chironomus riparius", "uaudnadndj")) # Narrow down results to a division or rank, or both diff --git a/man/get_ids.Rd b/man/get_ids.Rd index 9391caee..4bc18a54 100644 --- a/man/get_ids.Rd +++ b/man/get_ids.Rd @@ -6,16 +6,24 @@ \title{Retrieve taxonomic identifiers for a given taxon name.} \usage{ get_ids( - names, + sci_com, db = c("itis", "ncbi", "eol", "tropicos", "gbif", "nbn", "pow"), suppress = FALSE, + names = NULL, ... ) -get_ids_(names, db = get_ids_dbs, rows = NA, suppress = FALSE, ...) +get_ids_( + sci_com, + db = get_ids_dbs, + rows = NA, + suppress = FALSE, + names = NULL, + ... +) } \arguments{ -\item{names}{(character) Taxonomic name to query.} +\item{sci_com}{(character) Taxonomic name to query.} \item{db}{(character) database to query. One or more of \code{ncbi}, \code{itis}, \code{eol}, \code{tropicos}, \code{gbif}, \code{nbn}, or \code{pow}. By default db is set to search @@ -28,6 +36,8 @@ see \link{taxize-authentication}} \item{suppress}{(logical) suppress \pkg{cli} separators with the database name being queried. default: \code{FALSE}} +\item{names}{Deprecated, see \code{sci_com}} + \item{...}{Other arguments passed to \code{\link[=get_tsn]{get_tsn()}}, \code{\link[=get_uid]{get_uid()}}, \code{\link[=get_eolid]{get_eolid()}}, \code{\link[=get_tpsid]{get_tpsid()}}, \code{\link[=get_gbifid]{get_gbifid()}}, \code{\link[=get_nbnid]{get_nbnid()}}.} @@ -60,27 +70,27 @@ See \link{taxize-authentication} for help on authentication \dontrun{ # Plug in taxon names directly ## By default you get ids for all data sources -get_ids(names="Chironomus riparius") +get_ids("Chironomus riparius") # specify rows to limit choices available -get_ids(names="Poa annua", db="eol", rows=1) -get_ids(names="Poa annua", db="eol", rows=1:2) +get_ids("Poa annua", db="eol", rows=1) +get_ids("Poa annua", db="eol", rows=1:2) ## Or you can specify which source you want via the db parameter -get_ids(names="Chironomus riparius", db = 'ncbi') -get_ids(names="Salvelinus fontinalis", db = 'nbn') +get_ids("Chironomus riparius", db = 'ncbi') +get_ids("Salvelinus fontinalis", db = 'nbn') -get_ids(names=c("Chironomus riparius", "Pinus contorta"), db = 'ncbi') -get_ids(names=c("Chironomus riparius", "Pinus contorta"), +get_ids(c("Chironomus riparius", "Pinus contorta"), db = 'ncbi') +get_ids(c("Chironomus riparius", "Pinus contorta"), db = c('ncbi','itis')) -get_ids(names=c("Chironomus riparius", "Pinus contorta"), +get_ids(c("Chironomus riparius", "Pinus contorta"), db = c('ncbi','itis')) -get_ids(names="Pinus contorta", +get_ids("Pinus contorta", db = c('ncbi','itis','eol','tropicos')) -get_ids(names="ava avvva", db = c('ncbi','itis','eol','tropicos')) +get_ids("ava avvva", db = c('ncbi','itis','eol','tropicos')) # Pass on to other functions -out <- get_ids(names="Pinus contorta", +out <- get_ids("Pinus contorta", db = c('ncbi','itis','eol','tropicos')) classification(out$itis) synonyms(out$tropicos) diff --git a/man/get_iucn.Rd b/man/get_iucn.Rd index 7c27f10a..8ccefa8e 100644 --- a/man/get_iucn.Rd +++ b/man/get_iucn.Rd @@ -11,7 +11,7 @@ \alias{as.data.frame.iucn} \title{Get a IUCN Redlist taxon} \usage{ -get_iucn(x, messages = TRUE, key = NULL, ...) +get_iucn(sci, messages = TRUE, key = NULL, x = NULL, ...) as.iucn(x, check = TRUE, key = NULL) @@ -28,7 +28,7 @@ as.iucn(x, check = TRUE, key = NULL) \method{as.data.frame}{iucn}(x, ...) } \arguments{ -\item{x}{(character) A vector of scientific names. Or, a +\item{sci}{(character) A vector of scientific names. Or, a \code{taxon_state} object (see \link{taxon-state})} \item{messages}{logical; should progress be printed?} @@ -37,6 +37,9 @@ as.iucn(x, check = TRUE, key = NULL) \link[rredlist:rredlist-package]{rredlist::rredlist-package} for help on authenticating with IUCN Redlist} +\item{x}{For \code{get_iucn()}: Deprecated, see \code{sci}. For \code{as.iucn()}, various, +see examples} + \item{...}{Ignored} \item{check}{(logical) Check if ID matches any existing on the DB, only @@ -75,9 +78,9 @@ methods. } \examples{ \dontrun{ -get_iucn(x = "Branta canadensis") -get_iucn(x = "Branta bernicla") -get_iucn(x = "Panthera uncia") +get_iucn("Branta canadensis") +get_iucn("Branta bernicla") +get_iucn("Panthera uncia") # as coercion as.iucn(22732) diff --git a/man/get_natservid.Rd b/man/get_natservid.Rd index ab3f7227..f9adcaaf 100644 --- a/man/get_natservid.Rd +++ b/man/get_natservid.Rd @@ -13,11 +13,12 @@ \title{Get NatureServe taxonomic ID for a taxon name} \usage{ get_natservid( - query, + sci_com, searchtype = "scientific", ask = TRUE, messages = TRUE, rows = NA, + query = NULL, ... ) @@ -36,15 +37,16 @@ as.natservid(x, check = TRUE) \method{as.data.frame}{natservid}(x, ...) get_natservid_( - query, + sci_com, searchtype = "scientific", messages = TRUE, rows = NA, + query = NULL, ... ) } \arguments{ -\item{query}{character; A vector of common or scientific names. Or, a +\item{sci_com}{character; A vector of common or scientific names. Or, a \code{taxon_state} object (see \link{taxon-state})} \item{searchtype}{character; One of 'scientific' (default) or 'common'. @@ -64,6 +66,8 @@ natservid class object with one to many identifiers. See \code{get_natservid_()} to get back all, or a subset, of the raw data that you are presented during the ask process.} +\item{query}{Deprecated, see \code{sci_com}} + \item{...}{curl options passed on to \link[crul:verb-POST]{crul::verb-POST}} \item{x}{Input to \code{as.natservid}} diff --git a/man/get_nbnid.Rd b/man/get_nbnid.Rd index 8416d373..f3be3592 100644 --- a/man/get_nbnid.Rd +++ b/man/get_nbnid.Rd @@ -12,12 +12,13 @@ \title{Get the UK National Biodiversity Network ID from taxonomic names.} \usage{ get_nbnid( - name, + sci_com, ask = TRUE, messages = TRUE, rec_only = FALSE, rank = NULL, rows = NA, + name = NULL, ... ) @@ -34,16 +35,17 @@ as.nbnid(x, check = TRUE) \method{as.data.frame}{nbnid}(x, ...) get_nbnid_( - name, + sci_com, messages = TRUE, rec_only = FALSE, rank = NULL, rows = NA, + name = NULL, ... ) } \arguments{ -\item{name}{character; a vector of common or scientific names. Or, a +\item{sci_com}{character; a vector of common or scientific names. Or, a \code{taxon_state} object (see \link{taxon-state})} \item{ask}{logical; should get_nbnid be run in interactive mode? @@ -66,6 +68,8 @@ class object with one to many identifiers. See \code{\link[=get_nbnid_]{get_nbnid_()}} to get back all, or a subset, of the raw data that you are presented during the ask process.} +\item{name}{Deprecated, see \code{sci_com}} + \item{...}{Further args passed on to \code{nbn_search}} \item{x}{Input to \code{\link[=as.nbnid]{as.nbnid()}}} @@ -93,14 +97,14 @@ Get the UK National Biodiversity Network ID from taxonomic names. } \examples{ \dontrun{ -get_nbnid(name='Poa annua') -get_nbnid(name='Poa annua', rec_only=TRUE) -get_nbnid(name='Poa annua', rank='Species') -get_nbnid(name='Poa annua', rec_only=TRUE, rank='Species') -get_nbnid(name='Pinus contorta') +get_nbnid(sci_com='Poa annua') +get_nbnid(sci_com='Poa annua', rec_only=TRUE) +get_nbnid(sci_com='Poa annua', rank='Species') +get_nbnid(sci_com='Poa annua', rec_only=TRUE, rank='Species') +get_nbnid(sci_com='Pinus contorta') # The NBN service handles common names too -get_nbnid(name='red-winged blackbird') +get_nbnid(sci_com='red-winged blackbird') # specify rows to limit choices available get_nbnid('Poa ann') @@ -109,7 +113,7 @@ get_nbnid('Poa ann', rows=25) get_nbnid('Poa ann', rows=1:2) # When not found -get_nbnid(name="uaudnadndj") +get_nbnid(sci_com="uaudnadndj") get_nbnid(c("Zootoca vivipara", "uaudnadndj")) get_nbnid(c("Zootoca vivipara","Chironomus riparius", "uaudnadndj")) diff --git a/man/get_pow.Rd b/man/get_pow.Rd index 04a26e51..4ce6742e 100644 --- a/man/get_pow.Rd +++ b/man/get_pow.Rd @@ -12,13 +12,14 @@ \title{Get Kew's Plants of the World code for a taxon} \usage{ get_pow( - x, + sci_com, accepted = FALSE, ask = TRUE, messages = TRUE, rows = NA, family_filter = NULL, rank_filter = NULL, + x = NULL, ... ) @@ -34,10 +35,10 @@ as.pow(x, check = TRUE) \method{as.data.frame}{pow}(x, ...) -get_pow_(x, messages = TRUE, rows = NA, ...) +get_pow_(sci_com, messages = TRUE, rows = NA, x = NULL, ...) } \arguments{ -\item{x}{character; A vector of common or scientific names. Or, a +\item{sci_com}{character; A vector of common or scientific names. Or, a \code{taxon_state} object (see \link{taxon-state})} \item{accepted}{logical; If TRUE, removes names that are not accepted @@ -64,6 +65,9 @@ retrieved from NCBI. See \code{\link[=rank_ref]{rank_ref()}} for possible option Though note that some data sources use atypical ranks, so inspect the data itself for options. Optional. See \code{Filtering} below.} +\item{x}{For \code{get_pow()}: deprecated, see \code{sci_com}. For \code{as.pow}, various, +see examples} + \item{...}{Curl options passed on to \link[crul:HttpClient]{crul::HttpClient}} \item{check}{logical; Check if ID matches any existing on the DB, only @@ -94,12 +98,12 @@ Filtering narrows down to the set that matches your query, and removes the rest. \examples{ \dontrun{ -get_pow(x = "Helianthus") +get_pow(sci_com="Helianthus") get_pow(c("Helianthus","Quercus douglasii")) # Get back a subset -get_pow(x="Helianthus", rows = 1) -get_pow(x="Helianthus", rows = 1:10) +get_pow(sci_com="Helianthus", rows = 1) +get_pow(sci_com="Helianthus", rows = 1:10) # When not found get_pow("howdy") diff --git a/man/get_tolid.Rd b/man/get_tolid.Rd index 50b8fb2d..7175b40c 100644 --- a/man/get_tolid.Rd +++ b/man/get_tolid.Rd @@ -12,7 +12,7 @@ \alias{get_tolid_} \title{Get the OTT id for a search term} \usage{ -get_tolid(sciname, ask = TRUE, messages = TRUE, rows = NA, ...) +get_tolid(sci, ask = TRUE, messages = TRUE, rows = NA, sciname = NULL, ...) as.tolid(x, check = TRUE) @@ -28,10 +28,10 @@ as.tolid(x, check = TRUE) \method{as.data.frame}{tolid}(x, ...) -get_tolid_(sciname, messages = TRUE, rows = NA) +get_tolid_(sci, messages = TRUE, rows = NA, sciname = NULL) } \arguments{ -\item{sciname}{character; one or more scientific names. Or, a \code{taxon_state} +\item{sci}{character; one or more scientific names. Or, a \code{taxon_state} object (see \link{taxon-state})} \item{ask}{logical; should \code{get_tolid} be run in interactive mode? @@ -46,6 +46,8 @@ class object with one to many identifiers. See \code{\link[=get_tolid_]{get_toli to get back all, or a subset, of the raw data that you are presented during the ask process.} +\item{sciname}{Deprecated, see \code{sci}} + \item{...}{Ignored} \item{x}{Input to \code{as.tolid}} @@ -70,8 +72,8 @@ OpenTreeOfLife } \examples{ \dontrun{ -get_tolid(sciname = "Quercus douglasii") -get_tolid(sciname = "Chironomus riparius") +get_tolid(sci = "Quercus douglasii") +get_tolid(sci = "Chironomus riparius") get_tolid(c("Chironomus riparius","Quercus douglasii")) splist <- c("annona cherimola", 'annona muricata', "quercus robur", "shorea robusta", "pandanus patina", "oryza sativa", "durio zibethinus") @@ -105,7 +107,7 @@ data.frame(out) as.tolid( data.frame(out) ) # Get all data back -get_tolid_(sciname="Arni") +get_tolid_("Arni") get_tolid_("Arni", rows=1) get_tolid_("Arni", rows=1:2) get_tolid_(c("asdfadfasd","Pinus contorta")) diff --git a/man/get_tpsid.Rd b/man/get_tpsid.Rd index ca12155f..7d7952d3 100644 --- a/man/get_tpsid.Rd +++ b/man/get_tpsid.Rd @@ -13,13 +13,14 @@ \title{Get the NameID codes from Tropicos for taxonomic names.} \usage{ get_tpsid( - sciname, + sci, ask = TRUE, messages = TRUE, key = NULL, rows = NA, family = NULL, rank = NULL, + sciname = NULL, ... ) @@ -37,10 +38,10 @@ as.tpsid(x, check = TRUE) \method{as.data.frame}{tpsid}(x, ...) -get_tpsid_(sciname, messages = TRUE, key = NULL, rows = NA, ...) +get_tpsid_(sci, messages = TRUE, key = NULL, rows = NA, sciname = NULL, ...) } \arguments{ -\item{sciname}{(character) One or more scientific name's as a vector or list. Or, +\item{sci}{(character) One or more scientific name's as a vector or list. Or, a \code{taxon_state} object (see \link{taxon-state})} \item{ask}{logical; should get_tpsid be run in interactive mode? @@ -62,6 +63,8 @@ presented during the ask process.} options. Though note that some data sources use atypical ranks, so inspect the data itself for options. Optional. See \code{Filtering} below.} +\item{sciname}{Deprecated, see \code{sci}} + \item{...}{Other arguments passed to \code{\link[=tp_search]{tp_search()}}.} \item{x}{Input to \code{\link[=as.tpsid]{as.tpsid()}}} @@ -94,8 +97,8 @@ Filtering narrows down to the set that matches your query, and removes the rest. \examples{ \dontrun{ -get_tpsid(sciname='Poa annua') -get_tpsid(sciname='Pinus contorta') +get_tpsid(sci='Poa annua') +get_tpsid(sci='Pinus contorta') get_tpsid(c("Poa annua", "Pinus contorta")) @@ -129,7 +132,7 @@ get_tpsid("Poa", family = "orchidaceae") get_tpsid("Aga", fuzzy = TRUE, parent = "*idae") # pass to classification function to get a taxonomic hierarchy -classification(get_tpsid(sciname='Poa annua')) +classification(get_tpsid(sci='Poa annua')) # Convert a tpsid without class information to a tpsid class as.tpsid(get_tpsid("Pinus contorta")) # already a tpsid, returns the same diff --git a/man/get_tsn.Rd b/man/get_tsn.Rd index 2c2a7376..352cb840 100644 --- a/man/get_tsn.Rd +++ b/man/get_tsn.Rd @@ -13,12 +13,13 @@ \title{Get the TSN code for a search term.} \usage{ get_tsn( - searchterm, + sci_com, searchtype = "scientific", accepted = FALSE, ask = TRUE, messages = TRUE, rows = NA, + searchterm = NULL, ... ) @@ -37,16 +38,17 @@ as.tsn(x, check = TRUE) \method{as.data.frame}{tsn}(x, ...) get_tsn_( - searchterm, + sci_com, messages = TRUE, searchtype = "scientific", accepted = TRUE, rows = NA, + searchterm = NULL, ... ) } \arguments{ -\item{searchterm}{character; A vector of common or scientific names. +\item{sci_com}{character; A vector of common or scientific names. Or, a \code{taxon_state} object (see \link{taxon-state})} \item{searchtype}{character; One of 'scientific' or 'common', or any @@ -68,6 +70,8 @@ class object with one to many identifiers. See \code{\link[=get_tsn_]{get_tsn_()}} to get back all, or a subset, of the raw data that you are presented during the ask process.} +\item{searchterm}{Deprecated, see \code{sci_com}} + \item{...}{Ignored} \item{x}{Input to as.tsn} @@ -108,7 +112,7 @@ get_tsn("howdy") get_tsn(c("Chironomus riparius", "howdy")) # Using common names -get_tsn(searchterm="black bear", searchtype="common") +get_tsn("black bear", searchtype="common") # Convert a tsn without class information to a tsn class as.tsn(get_tsn("Quercus douglasii")) # already a tsn, returns the same diff --git a/man/get_uid.Rd b/man/get_uid.Rd index 3a0d36bf..44c223e8 100644 --- a/man/get_uid.Rd +++ b/man/get_uid.Rd @@ -13,7 +13,7 @@ \title{Get the UID codes from NCBI for taxonomic names.} \usage{ get_uid( - sciname, + sci_com, ask = TRUE, messages = TRUE, rows = NA, @@ -22,6 +22,7 @@ get_uid( division_filter = NULL, rank_filter = NULL, key = NULL, + sciname = NULL, ... ) @@ -39,10 +40,10 @@ as.uid(x, check = TRUE) \method{as.data.frame}{uid}(x, ...) -get_uid_(sciname, messages = TRUE, rows = NA, key = NULL, ...) +get_uid_(sci_com, messages = TRUE, rows = NA, key = NULL, sciname = NULL, ...) } \arguments{ -\item{sciname}{character; scientific name. Or, a \code{taxon_state} +\item{sci_com}{character; scientific or common name. Or, a \code{taxon_state} object (see \link{taxon-state})} \item{ask}{logical; should get_uid be run in interactive mode? If TRUE and @@ -58,7 +59,7 @@ class object with one to many identifiers. See \code{\link[=get_uid_]{get_uid_() all, or a subset, of the raw data that you are presented during the ask process.} -\item{modifier}{(character) A modifier to the \code{sciname} given. Options +\item{modifier}{(character) A modifier to the \code{sci_com} given. Options include: Organism, Scientific Name, Common Name, All Names, Division, Filter, Lineage, GC, MGC, Name Tokens, Next Level, PGC, Properties, Rank, Subtree, Synonym, Text Word. These are not checked, so make sure they are @@ -79,6 +80,8 @@ itself for options. Optional. See \code{Filtering} below.} \item{key}{(character) NCBI Entrez API key. optional. See Details.} +\item{sciname}{Deprecated, see \code{sci_com}} + \item{...}{Ignored} \item{x}{Input to \code{\link[=as.uid]{as.uid()}}} @@ -154,12 +157,12 @@ get_uid(c("Chironomus riparius", "howdy")) # Narrow down results to a division or rank, or both ## By modifying the query ### w/ modifiers to the name -get_uid(sciname = "Aratinga acuticauda", modifier = "Organism") -get_uid(sciname = "bear", modifier = "Common Name") +get_uid(sci_com = "Aratinga acuticauda", modifier = "Organism") +get_uid(sci_com = "bear", modifier = "Common Name") ### w/ rank query -get_uid(sciname = "Pinus", rank_query = "genus") -get_uid(sciname = "Pinus", rank_query = "subgenus") +get_uid(sci_com = "Pinus", rank_query = "genus") +get_uid(sci_com = "Pinus", rank_query = "subgenus") ### division query doesn't really work, for unknown reasons, so not available ## By filtering the result @@ -167,20 +170,20 @@ get_uid(sciname = "Pinus", rank_query = "subgenus") ### Results w/o narrowing get_uid("Echinacea") ### w/ division -get_uid(sciname = "Echinacea", division_filter = "eudicots") -get_uid(sciname = "Echinacea", division_filter = "sea urchins") +get_uid(sci_com = "Echinacea", division_filter = "eudicots") +get_uid(sci_com = "Echinacea", division_filter = "sea urchins") ## Satyrium example ### Results w/o narrowing -get_uid(sciname = "Satyrium") +get_uid(sci_com = "Satyrium") ### w/ division -get_uid(sciname = "Satyrium", division_filter = "monocots") -get_uid(sciname = "Satyrium", division_filter = "butterflies") +get_uid(sci_com = "Satyrium", division_filter = "monocots") +get_uid(sci_com = "Satyrium", division_filter = "butterflies") ## Rank example -get_uid(sciname = "Pinus") -get_uid(sciname = "Pinus", rank_filter = "genus") -get_uid(sciname = "Pinus", rank_filter = "subgenus") +get_uid(sci_com = "Pinus") +get_uid(sci_com = "Pinus", rank_filter = "genus") +get_uid(sci_com = "Pinus", rank_filter = "subgenus") # Fuzzy filter on any filtering fields ## uses grep on the inside diff --git a/man/get_wiki.Rd b/man/get_wiki.Rd index b6ba6317..f36951d8 100644 --- a/man/get_wiki.Rd +++ b/man/get_wiki.Rd @@ -13,13 +13,14 @@ \title{Get the page name for a Wiki taxon} \usage{ get_wiki( - x, + sci_com, wiki_site = "species", wiki = "en", ask = TRUE, messages = TRUE, limit = 100, rows = NA, + x = NULL, ... ) @@ -48,7 +49,7 @@ get_wiki_( ) } \arguments{ -\item{x}{(character) A vector of common or scientific names. Or, a +\item{sci_com}{(character) A vector of common or scientific names. Or, a \code{taxon_state} object (see \link{taxon-state})} \item{wiki_site}{(character) Wiki site. One of species (default), pedia, @@ -70,6 +71,9 @@ class object with one to many identifiers. See \code{\link[=get_wiki_]{get_wiki_ all, or a subset, of the raw data that you are presented during the ask process.} +\item{x}{For \code{get_wiki()}: deprecated, see \code{sci_com}. For \code{as.wiki}, various, +see examples} + \item{...}{Ignored} \item{check}{logical; Check if ID matches any existing on the DB, only @@ -95,10 +99,10 @@ default. Set the \code{wiki} parameter for a different language site. } \examples{ \dontrun{ -get_wiki(x = "Quercus douglasii") -get_wiki(x = "Quercu") -get_wiki(x = "Quercu", "pedia") -get_wiki(x = "Quercu", "commons") +get_wiki(sci_com = "Quercus douglasii") +get_wiki(sci_com = "Quercu") +get_wiki(sci_com = "Quercu", "pedia") +get_wiki(sci_com = "Quercu", "commons") # diff. wikis with wikipedia get_wiki("Malus domestica", "pedia") diff --git a/man/get_wormsid.Rd b/man/get_wormsid.Rd index c02e5002..7e673f52 100644 --- a/man/get_wormsid.Rd +++ b/man/get_wormsid.Rd @@ -13,7 +13,7 @@ \title{Get Worms ID for a taxon name} \usage{ get_wormsid( - query, + sci_com, searchtype = "scientific", marine_only = TRUE, fuzzy = NULL, @@ -21,6 +21,7 @@ get_wormsid( ask = TRUE, messages = TRUE, rows = NA, + query = NULL, ... ) @@ -39,18 +40,19 @@ as.wormsid(x, check = TRUE) \method{as.data.frame}{wormsid}(x, ...) get_wormsid_( - query, + sci_com, messages = TRUE, searchtype = "scientific", marine_only = TRUE, fuzzy = NULL, accepted = TRUE, rows = NA, + query = NULL, ... ) } \arguments{ -\item{query}{character; A vector of common or scientific names. Or, a +\item{sci_com}{character; A vector of common or scientific names. Or, a \code{taxon_state} object (see \link{taxon-state})} \item{searchtype}{character; One of 'scientific' or 'common', or any unique @@ -81,9 +83,11 @@ class object with one to many identifiers. See \code{\link[=get_wormsid_]{get_wo all, or a subset, of the raw data that you are presented during the ask process.} +\item{query}{Deprecated, see \code{sci_com}} + \item{...}{Ignored} -\item{x}{Input to as.wormsid} +\item{x}{Input to \code{as.wormsid}} \item{check}{logical; Check if ID matches any existing on the DB, only used in \code{\link[=as.wormsid]{as.wormsid()}}} diff --git a/man/gni_search.Rd b/man/gni_search.Rd index a96cb8c4..977dd42e 100644 --- a/man/gni_search.Rd +++ b/man/gni_search.Rd @@ -5,35 +5,34 @@ \title{Search for taxonomic names using the Global Names Index} \usage{ gni_search( - search_term = NULL, + sci, per_page = NULL, page = NULL, justtotal = FALSE, parse_names = FALSE, + search_term = NULL, ... ) } \arguments{ -\item{search_term}{Name pattern you want to search for. WARNING: Does -not work for vernacular/common names. Search term may include following -options (Note: can, uni, gen, sp, ssp, au, yr work only for parsed names -\itemize{ -\item +\item{sci}{(character) required. Name pattern you want to search +for. WARNING: Does not work for common names. Search term may include +following options (Note: can, uni, gen, sp, ssp, au, yr work only for +parsed names) \itemize{ -\item wild card - Search by part of a word (E.g.: planta*) -} -\item exact exact match - Search for exact match of a literal string +\item \code{*} wild card - Search by part of a word (E.g.: planta*) +\item \code{exact} exact match - Search for exact match of a literal string (E.g.: exact:Parus major) -\item ns name string- Search for literal string from its beginning (other +\item \code{ns} name string- Search for literal string from its beginning (other modifiers will be ignored) (E.g.: ns:parus maj*) -\item can canonical form- Search name without authors (other modifiers will +\item \code{can} canonical form- Search name without authors (other modifiers will be ignored) (E.g.: can:parus major) -\item uni uninomial- Search for higher taxa (E.g.: uni:parus) -\item gen genus - Search by genus epithet of species name (E.g.: gen:parus) -\item sp species - Search by species epithet (E.g.: sp:major) -\item ssp subspecies - Search by infraspecies epithet (E.g.: ssp:major) -\item au author - Search by author word (E.g.: au:Shipunov) -\item yr year - Search by year (E.g.: yr:2005) +\item \code{uni} uninomial- Search for higher taxa (E.g.: uni:parus) +\item \code{gen} genus - Search by genus epithet of species name (E.g.: gen:parus) +\item \code{sp} species - Search by species epithet (E.g.: sp:major) +\item \code{ssp} subspecies - Search by infraspecies epithet (E.g.: ssp:major) +\item \code{au} author - Search by author word (E.g.: au:Shipunov) +\item \code{yr} year - Search by year (E.g.: yr:2005) }} \item{per_page}{Number of items per one page (numbers larger @@ -46,6 +45,8 @@ than 1000 will be decreased to 1000) (default is 30).} \item{parse_names}{If \code{TRUE}, use \code{\link[=gni_parse]{gni_parse()}} to parse names. Default: \code{FALSE}} +\item{search_term}{Deprecated, see \code{sci}} + \item{...}{Curl options passed on to \link[crul:verb-GET]{crul::verb-GET}} } \value{ @@ -60,15 +61,15 @@ asterisk to the end of a search term. See the first two examples below } \examples{ \dontrun{ -gni_search(search_term = "ani*") -gni_search(search_term = "ama*", per_page = 3, page = 21) -gni_search(search_term = "animalia", per_page = 8, page = 1) -gni_search(search_term = "animalia", per_page = 8, page = 1, justtotal=TRUE) +gni_search(sci = "ani*") +gni_search(sci = "ama*", per_page = 3, page = 21) +gni_search(sci = "animalia", per_page = 8, page = 1) +gni_search(sci = "animalia", per_page = 8, page = 1, justtotal=TRUE) -gni_search(search_term = "Cyanistes caeruleus", parse_names=TRUE) +gni_search(sci = "Cyanistes caeruleus", parse_names=TRUE) # pass on curl options -gni_search(search_term = "ani*", verbose = TRUE) +gni_search(sci = "ani*", verbose = TRUE) } } \references{ diff --git a/man/nbn_search.Rd b/man/nbn_search.Rd index 012e9878..134f3ac7 100644 --- a/man/nbn_search.Rd +++ b/man/nbn_search.Rd @@ -5,18 +5,19 @@ \title{Search UK National Biodiversity Network} \usage{ nbn_search( - q, + sci_com, fq = NULL, order = NULL, sort = NULL, start = 0, rows = 25, facets = NULL, + q = NULL, ... ) } \arguments{ -\item{q}{(character) The query terms(s)} +\item{sci_com}{(character) The query terms(s), a scientific or common name} \item{fq}{(character) Filters to be applied to the original query. These are additional params of the form fq=INDEXEDFIELD:VALUE e.g. @@ -34,6 +35,8 @@ the fields that are queryable.} \item{facets}{(list) Comma separated list of the fields to create facets on e.g. facets=basis_of_record.} +\item{q}{Deprecated, see \code{sci}} + \item{...}{Further args passed on to \link[crul:HttpClient]{crul::HttpClient}.} } \value{ @@ -45,17 +48,17 @@ Search UK National Biodiversity Network } \examples{ \dontrun{ -x <- nbn_search(q = "Vulpes") +x <- nbn_search(sci_com = "Vulpes") x$meta$totalRecords x$meta$pageSize x$meta$urlParameters x$meta$queryTitle head(x$data) -nbn_search(q = "blackbird", start = 4) +nbn_search(sci_com = "blackbird", start = 4) # debug curl stuff -nbn_search(q = "blackbird", verbose = TRUE) +nbn_search(sci_com = "blackbird", verbose = TRUE) } } \references{ diff --git a/man/pow_search.Rd b/man/pow_search.Rd index ba776a9c..eff74d26 100644 --- a/man/pow_search.Rd +++ b/man/pow_search.Rd @@ -4,10 +4,10 @@ \alias{pow_search} \title{Search Kew's Plants of the World} \usage{ -pow_search(q, limit = 100, cursor = "*", sort = NULL, ...) +pow_search(sci_com, limit = 100, cursor = "*", sort = NULL, q = NULL, ...) } \arguments{ -\item{q}{(character) query terms} +\item{sci_com}{(character) query terms, scientific or common name} \item{limit}{(integer) Number of records to return. default: 100} @@ -16,6 +16,8 @@ pow_search(q, limit = 100, cursor = "*", sort = NULL, ...) \item{sort}{(character) The field to sort by and sort order separted with underscore, e.g., \code{sort="name_desc"}} +\item{q}{Deprecated, see \code{sci_com}} + \item{...}{Further args passed on to \link[crul:HttpClient]{crul::HttpClient}.} } \value{ @@ -27,7 +29,7 @@ Search Kew's Plants of the World } \examples{ \dontrun{ -x <- pow_search(q = "Quercus") +x <- pow_search(sci_com = "Quercus") x$meta x$meta$totalResults x$meta$perPage @@ -37,15 +39,15 @@ x$meta$cursor head(x$data) # pagination -pow_search(q = "sunflower", limit = 2) +pow_search(sci_com = "sunflower", limit = 2) # debug curl stuff -invisible(pow_search(q = "Helianthus annuus", verbose = TRUE)) +invisible(pow_search(sci_com = "Helianthus annuus", verbose = TRUE)) # sort -desc <- pow_search(q = "Helianthus", sort = "name_desc") +desc <- pow_search(sci_com = "Helianthus", sort = "name_desc") desc$data$name -asc <- pow_search(q = "Helianthus", sort = "name_asc") +asc <- pow_search(sci_com = "Helianthus", sort = "name_asc") asc$data$name } } diff --git a/man/taxize-params.Rd b/man/taxize-params.Rd new file mode 100644 index 00000000..046ff233 --- /dev/null +++ b/man/taxize-params.Rd @@ -0,0 +1,26 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/taxize-params.R +\name{taxize-params} +\alias{taxize-params} +\title{taxize parameters} +\description{ +Information on standardized parameters across the package +} +\section{Standardized parameters}{ + +\itemize{ +\item \code{sci}: scientific name +\item \code{com}: common name +\item \code{id}: name identifier +\item \code{sci_com}: scientific name or common name +\item \code{sci_id}: scientific name or name identifier +} + +We were going to standardize parameter names for cases in which +a parameter accepts either of three options: scientific name, +common name, or name identifier. However, there was no clear +parameter name we could use for this case, so we've left +parameter names as they are for the two cases (\code{\link[=get_ids]{get_ids()}} and +\code{\link[=vascan_search]{vascan_search()}}) +} + diff --git a/man/tp_search.Rd b/man/tp_search.Rd index fa39546d..78458631 100644 --- a/man/tp_search.Rd +++ b/man/tp_search.Rd @@ -5,8 +5,8 @@ \title{Search Tropicos by scientific name, common name, or Tropicos ID.} \usage{ tp_search( - name = NULL, - commonname = NULL, + sci = NULL, + com = NULL, nameid = NULL, orderby = NULL, sortorder = NULL, @@ -14,30 +14,36 @@ tp_search( startrow = NULL, type = NULL, key = NULL, + name = NULL, + commonname = NULL, ... ) } \arguments{ -\item{name}{Your search string. For instance "poa annua". See Details.} +\item{sci}{A scientific name, e.g., "poa annua". See Details.} -\item{commonname}{Your search string. For instance "annual blue grass"} +\item{com}{A common name, e.g., "annual blue grass"} -\item{nameid}{Your search string. For instance "25509881"} +\item{nameid}{Your search string. e.g., "25509881"} -\item{orderby}{Your search string. For instance "1"} +\item{orderby}{Your search string. e.g., "1"} -\item{sortorder}{Your search string. For instance "ascending"} +\item{sortorder}{Your search string. e.g., "ascending"} -\item{pagesize}{Your search string. For instance "100"} +\item{pagesize}{Your search string. e.g., "100"} -\item{startrow}{Your search string. For instance "1"} +\item{startrow}{Your search string. e.g., "1"} -\item{type}{Type of search, "wildcard" (default) will add a wildcard to the end -of your search string. "exact" will use your search string exactly.} +\item{type}{Type of search, "wildcard" (default) will add a wildcard to +the end of your search string. "exact" will use your search string exactly.} \item{key}{Your Tropicos API key; See \link{taxize-authentication} for help on authentication} +\item{name}{Deprecated, see \code{sci}} + +\item{commonname}{Deprecated, see \code{com}} + \item{...}{Further args passed on to \link[crul:HttpClient]{crul::HttpClient}} } \value{ @@ -55,11 +61,11 @@ names like \code{var}/\code{subsp}, so remove those from your query. } \examples{ \dontrun{ -tp_search(name = 'Poa annua') -tp_search(name = 'Poa annua subsp. annua') -tp_search(name = 'Poa annua var. annua') -tp_search(name = 'Poa annua var annua') -tp_search(name = 'Poa annua annua') +tp_search(sci = 'Poa annua') +tp_search(sci = 'Poa annua subsp. annua') +tp_search(sci = 'Poa annua var. annua') +tp_search(sci = 'Poa annua var annua') +tp_search(sci = 'Poa annua annua') } } \references{ diff --git a/tests/testthat/test-bold_search.R b/tests/testthat/test-bold_search.R index d2a56aa5..a21aab68 100644 --- a/tests/testthat/test-bold_search.R +++ b/tests/testthat/test-bold_search.R @@ -1,9 +1,9 @@ test_that("bold_search returns the correct value, dimensions, and classes", { skip_on_cran() vcr::use_cassette("bold_search", { - a <- bold_search(name = "Apis") - b <- bold_search(name = "Aga", fuzzy = TRUE) - c <- bold_search(name = c("Apis", "Puma concolor")) + a <- bold_search(sci = "Apis") + b <- bold_search(sci = "Aga", fuzzy = TRUE) + c <- bold_search(sci = c("Apis", "Puma concolor")) d <- bold_search(id = 88899) }) @@ -25,8 +25,8 @@ test_that("bold_search returns the correct value, dimensions, and classes", { test_that("bold_search is robust to user error", { skip_on_cran() - expect_is(bold_search(name = "asdfsdf"), "data.frame") - expect_is(bold_search(name = ""), "data.frame") + expect_is(bold_search(sci = "asdfsdf"), "data.frame") + expect_is(bold_search(sci = ""), "data.frame") expect_is(bold_search(id = "asdfsdf"), "data.frame") expect_error(bold_search()) }) diff --git a/tests/testthat/test-eol_search.R b/tests/testthat/test-eol_search.R index e6a0661c..42b89ec2 100644 --- a/tests/testthat/test-eol_search.R +++ b/tests/testthat/test-eol_search.R @@ -5,7 +5,7 @@ test_that("eol_search returns the correct value", { skip_on_cran() vcr::use_cassette("eol_search", { - aa <- eol_search(terms='Ursus americanus') + aa <- eol_search(sci='Ursus americanus') }) expect_is(aa, "data.frame") diff --git a/tests/testthat/test-get_boldid.R b/tests/testthat/test-get_boldid.R index 0c85df1a..468dc435 100644 --- a/tests/testthat/test-get_boldid.R +++ b/tests/testthat/test-get_boldid.R @@ -4,8 +4,8 @@ context("get_boldid") test_that("get_boldid returns the correct value", { skip_on_cran() vcr::use_cassette("get_boldid", { - expect_equal(get_boldid(searchterm = 'Helianthus', messages = FALSE)[[1]], '125295') - expect_true(is.na(get_boldid(searchterm='adsf asdf asdf', messages=FALSE)[[1]])) + expect_equal(get_boldid(sci = 'Helianthus', messages = FALSE)[[1]], '125295') + expect_true(is.na(get_boldid(sci='adsf asdf asdf', messages=FALSE)[[1]])) expect_is(get_boldid(c("Helianthus excubitor", "adsf asdf asdf"), messages=FALSE), "boldid") }) @@ -32,7 +32,7 @@ test_that("get_boldid works when there's no parent name", { test_that("get_boldid fails as expected", { skip_on_cran() - expect_error(get_boldid(), "argument \"searchterm\" is missing") + expect_error(get_boldid(), "argument \"sci\" is missing") expect_error(get_boldid("Satyrium", ask = 4, messages = FALSE), "ask must be of class logical") expect_error( diff --git a/tests/testthat/test-get_eolid.R b/tests/testthat/test-get_eolid.R index 2c6cde95..97f5da2d 100644 --- a/tests/testthat/test-get_eolid.R +++ b/tests/testthat/test-get_eolid.R @@ -4,7 +4,7 @@ test_that("get_eolid works", { skip_on_cran() vcr::use_cassette("get_eolid", { - a <- get_eolid(sciname = "Puma concolor", messages = FALSE, rows = 1) + a <- get_eolid(sci_com = "Puma concolor", messages = FALSE, rows = 1) }) expect_is(a, "eolid") @@ -22,7 +22,7 @@ test_that("get_eolid accepts ask-argument", { skip_on_cran() vcr::use_cassette("get_eolid_ask_param", { - expect_true(is.na(get_eolid(sciname = 'adsf asdf asdf', ask = FALSE, + expect_true(is.na(get_eolid(sci_com = 'adsf asdf asdf', ask = FALSE, messages = FALSE)[[1]])) }) }) @@ -30,7 +30,7 @@ test_that("get_eolid accepts ask-argument", { test_that("get_eolid fails as expected", { skip_on_cran() - expect_error(get_eolid(), "argument \"sciname\" is missing") + expect_error(get_eolid(), "argument \"sci_com\" is missing") expect_error(get_eolid("Poa annua", ask = 4, messages = FALSE), "ask must be of class logical") diff --git a/tests/testthat/test-get_gbifid.R b/tests/testthat/test-get_gbifid.R index 8a9f8e05..a9d1ffc6 100644 --- a/tests/testthat/test-get_gbifid.R +++ b/tests/testthat/test-get_gbifid.R @@ -24,7 +24,7 @@ test_that("get_gbifid accepts ask-argument", { test_that("get_gbifid method parameter works", { skip_on_cran() vcr::use_cassette("get_gbifid_method_param", { - mod1 <- get_gbifid_(sciname = "Z*", method = "backbone", messages = FALSE, + mod1 <- get_gbifid_(sci = "Z*", method = "backbone", messages = FALSE, rows = 1:100) mod2 <- get_gbifid_("Z*", method = "lookup", messages = FALSE, rows = 1:100) @@ -54,8 +54,8 @@ test_that("get_gbifid phylum/class/order/family parameters work", { # skip_on_cran() # ## Rank example -# rf1 <- get_gbifid(sciname = "Bison", rank = "genus", rows = 1, messages = FALSE) -# rf2 <- get_gbifid(sciname = "Bison bison", rank = "species", rows = 1, messages = FALSE) +# rf1 <- get_gbifid(sci = "Bison", rank = "genus", rows = 1, messages = FALSE) +# rf2 <- get_gbifid(sci = "Bison bison", rank = "species", rows = 1, messages = FALSE) # expect_is(rf1, "gbifid") # expect_is(rf2, "gbifid") @@ -80,7 +80,7 @@ test_that("works regardless of character or numeric GGBIF ID given back", { test_that("get_gbifid fails as expected", { skip_on_cran() - expect_error(get_gbifid(), "argument \"sciname\" is missing") + expect_error(get_gbifid(), "argument \"sci\" is missing") expect_error(get_gbifid('Poa annua', ask = 4, messages = FALSE), "ask must be of class logical") expect_error( diff --git a/tests/testthat/test-get_ids.R b/tests/testthat/test-get_ids.R index 7db0d0fa..e5a9fa54 100644 --- a/tests/testthat/test-get_ids.R +++ b/tests/testthat/test-get_ids.R @@ -5,7 +5,7 @@ context("get_ids") test_that("get_ids returns the correct values and classses", { skip_on_cran() - tt <- get_ids(names = "Chironomus riparius", db = "ncbi", + tt <- get_ids("Chironomus riparius", db = "ncbi", messages = FALSE, suppress = TRUE) expect_equal(tt[[1]][[1]], "315576") @@ -17,9 +17,9 @@ test_that("get_ids returns the correct values and classses", { test_that("get_ids accepts ask and verbose arguments", { skip_on_cran() - expect_message(get_ids(names = "Pinus contorta", db = "ncbi", + expect_message(get_ids("Pinus contorta", db = "ncbi", suppress = TRUE)) - expect_message(get_ids(names = "Pinus contorta", db = "ncbi", + expect_message(get_ids("Pinus contorta", db = "ncbi", messages = FALSE, suppress = TRUE), NA) }) diff --git a/tests/testthat/test-get_natservid.R b/tests/testthat/test-get_natservid.R index c999c61a..8cbd6958 100644 --- a/tests/testthat/test-get_natservid.R +++ b/tests/testthat/test-get_natservid.R @@ -28,7 +28,7 @@ test_that("get_natservid fails well", { expect_true(is.na(get_natservid("asdfadsf", messages = FALSE))) - expect_error(get_natservid(), "argument \"query\" is missing") + expect_error(get_natservid(), "argument \"sci_com\" is missing") expect_error(get_natservid("clam", 5), "searchtype must be of class character") expect_error(get_natservid("clam", "stuff", messages = FALSE), diff --git a/tests/testthat/test-get_pow.R b/tests/testthat/test-get_pow.R index ec4e25fc..eebc8fce 100644 --- a/tests/testthat/test-get_pow.R +++ b/tests/testthat/test-get_pow.R @@ -24,7 +24,7 @@ test_that("get_pow accepts ask-argument", { test_that("get_pow fails as expected", { skip_on_cran() - expect_error(get_pow(), "argument \"x\" is missing") + expect_error(get_pow(), "argument \"sci_com\" is missing") expect_error(get_pow("Poa annua", ask = 4, messages = FALSE), "ask must be of class logical") expect_error( diff --git a/tests/testthat/test-get_tolid.R b/tests/testthat/test-get_tolid.R index 8c7150eb..7fe4953b 100644 --- a/tests/testthat/test-get_tolid.R +++ b/tests/testthat/test-get_tolid.R @@ -28,7 +28,7 @@ test_that("get_tolid accepts ask-argument", { test_that("get_tolid fails as expected", { skip_on_cran() - expect_error(get_tolid(), "argument \"sciname\" is missing") + expect_error(get_tolid(), "argument \"sci\" is missing") expect_error(get_tolid("Satyrium", ask = 4, messages = FALSE), "ask must be of class logical") diff --git a/tests/testthat/test-get_tpsid.R b/tests/testthat/test-get_tpsid.R index 91651cf7..6f474c72 100644 --- a/tests/testthat/test-get_tpsid.R +++ b/tests/testthat/test-get_tpsid.R @@ -3,8 +3,8 @@ context("get_tpsid") test_that("get_tpsid returns the correct value", { skip_on_cran() # uses secrets vcr::use_cassette("get_tpsid", { - a <- get_tpsid(sciname='Helianthus excubitor', messages=FALSE)[[1]] - b <- get_tpsid(sciname='adsf asdf asdf', messages=FALSE)[[1]] + a <- get_tpsid(sci='Helianthus excubitor', messages=FALSE)[[1]] + b <- get_tpsid(sci='adsf asdf asdf', messages=FALSE)[[1]] d <- get_tpsid(c("Helianthus excubitor", "adsf asdf asdf"), messages=FALSE) }) @@ -16,7 +16,7 @@ test_that("get_tpsid returns the correct value", { test_that("get_tpsid accepts ask-argument", { skip_on_cran() # uses secrets vcr::use_cassette("get_tpsid_ask_arg", { - a <- get_tpsid(sciname='adsf asdf asdf', ask=FALSE, messages=FALSE)[[1]] + a <- get_tpsid(sci='adsf asdf asdf', ask=FALSE, messages=FALSE)[[1]] }) expect_true(is.na(a)) @@ -53,7 +53,7 @@ test_that("get_tpsid behaves correctly on subspecific inputs", { test_that("get_tpsid fails as expected", { skip_on_cran() - expect_error(get_tpsid(), "argument \"sciname\" is missing") + expect_error(get_tpsid(), "argument \"sci\" is missing") expect_error(get_tpsid('Poa annua', ask = 4, messages = FALSE), "ask must be of class logical") diff --git a/tests/testthat/test-get_tsn.R b/tests/testthat/test-get_tsn.R index 6ff1e4ce..97e72eb8 100644 --- a/tests/testthat/test-get_tsn.R +++ b/tests/testthat/test-get_tsn.R @@ -23,11 +23,11 @@ test_that("get_tsn accepts ask and verbose arguments", { test_that("get_tsn fails as expected", { skip_on_cran() - expect_error(get_tsn(), "argument \"searchterm\" is missing") + expect_error(get_tsn(), "argument \"sci_com\" is missing") expect_error(get_tsn("Arni", ask = 4, messages = FALSE), "ask must be of class logical") expect_error( - get_tsn(searchterm="black bear", searchtype=5, + get_tsn(sci_com="black bear", searchtype=5, messages = FALSE), "searchtype must be of class character") expect_error( @@ -37,7 +37,7 @@ test_that("get_tsn fails as expected", { # searchtype values expect_error( - get_tsn(searchterm="black bear", searchtype="asdfadf", + get_tsn(sci_com="black bear", searchtype="asdfadf", messages = FALSE), "'arg' should be one of") diff --git a/tests/testthat/test-get_uid.R b/tests/testthat/test-get_uid.R index 27f292b0..13f290d4 100644 --- a/tests/testthat/test-get_uid.R +++ b/tests/testthat/test-get_uid.R @@ -22,8 +22,8 @@ test_that("get_uid accepts ask-argument", { test_that("get_uid query modifiers work", { skip_on_cran() # uses secrets vcr::use_cassette("get_uid_name_modifiers", { - mod1 <- get_uid(sciname = "Aratinga", messages = FALSE) - mod2 <- get_uid(sciname = "Aratinga", modifier = "Organism", + mod1 <- get_uid(sci_com = "Aratinga", messages = FALSE) + mod2 <- get_uid(sci_com = "Aratinga", modifier = "Organism", rows = 1, messages = FALSE) }) @@ -33,8 +33,8 @@ test_that("get_uid query modifiers work", { expect_equal(mod2[[1]], "1230190") vcr::use_cassette("get_uid_rank_modifiers", { - rq1 <- get_uid(sciname = "Pinus", rank_query = "genus", messages = FALSE) - rq2 <- get_uid(sciname = "Pinus", rank_query = "subgenus", messages = FALSE) + rq1 <- get_uid(sci_com = "Pinus", rank_query = "genus", messages = FALSE) + rq2 <- get_uid(sci_com = "Pinus", rank_query = "subgenus", messages = FALSE) }) expect_is(rq1, "uid") @@ -46,9 +46,9 @@ test_that("get_uid query modifiers work", { test_that("get_uid filtering works", { skip_on_cran() # uses secrets vcr::use_cassette("get_uid_filtering_division", { - df1 <- get_uid(sciname = "Echinacea", division_filter = "eudicots", + df1 <- get_uid(sci_com = "Echinacea", division_filter = "eudicots", messages = FALSE) - df2 <- get_uid(sciname = "Echinacea", division_filter = "sea urchins", + df2 <- get_uid(sci_com = "Echinacea", division_filter = "sea urchins", messages = FALSE) }) @@ -58,9 +58,9 @@ test_that("get_uid filtering works", { expect_equal(df2[[1]], "7674") vcr::use_cassette("get_uid_filtering_rank", { - rf1 <- get_uid(sciname = "Pinus", rank_filter = "genus", rows = 2, + rf1 <- get_uid(sci_com = "Pinus", rank_filter = "genus", rows = 2, messages = FALSE) - rf2 <- get_uid(sciname = "Pinus", rank_filter = "subgenus", + rf2 <- get_uid(sci_com = "Pinus", rank_filter = "subgenus", messages = FALSE) }) @@ -73,23 +73,23 @@ test_that("get_uid filtering works", { test_that("get_uid fails as expected", { skip_on_cran() - expect_error(get_uid(), "argument \"sciname\" is missing") + expect_error(get_uid(), "argument \"sci_com\" is missing") expect_error(get_uid("Satyrium", ask = 4, messages = FALSE), "ask must be of class logical") expect_error( - get_uid(sciname = "Aratinga acuticauda", modifier = 5, + get_uid(sci_com = "Aratinga acuticauda", modifier = 5, messages = FALSE), "modifier must be of class character") expect_error( - get_uid(sciname = "Pinus", rank_query = TRUE, + get_uid(sci_com = "Pinus", rank_query = TRUE, messages = FALSE), "rank_query must be of class character") expect_error( - get_uid(sciname = "Echinacea", division_filter = 4, + get_uid(sci_com = "Echinacea", division_filter = 4, messages = FALSE), "division_filter must be of class character") expect_error( - get_uid(sciname = "Pinus", rank_filter = 34, + get_uid(sci_com = "Pinus", rank_filter = 34, messages = FALSE), "rank_filter must be of class character") diff --git a/tests/testthat/test-get_wormsid.R b/tests/testthat/test-get_wormsid.R index 6ca6fd2f..4ba35193 100644 --- a/tests/testthat/test-get_wormsid.R +++ b/tests/testthat/test-get_wormsid.R @@ -71,7 +71,7 @@ test_that("get_wormsid fails well", { }) skip_on_cran() - expect_error(get_wormsid(), "argument \"query\" is missing") + expect_error(get_wormsid(), "argument \"sci_com\" is missing") expect_error(get_wormsid("clam", 5, messages = FALSE), "searchtype must be of class character") expect_error(get_wormsid("clam", "stuff", messages = FALSE), diff --git a/tests/testthat/test-gni_search.R b/tests/testthat/test-gni_search.R index 07fe56a2..b12a8dc7 100644 --- a/tests/testthat/test-gni_search.R +++ b/tests/testthat/test-gni_search.R @@ -3,7 +3,7 @@ context("gni_search") test_that("gni_search returns the correct value", { skip_on_cran() vcr::use_cassette("gni_search", { - x <- gni_search(search_term = "ama*", per_page = 1) + x <- gni_search(sci = "ama*", per_page = 1) }) expect_is(x, "data.frame") diff --git a/tests/testthat/test-pow_search.R b/tests/testthat/test-pow_search.R index 3cfa812c..f1b0fdd1 100644 --- a/tests/testthat/test-pow_search.R +++ b/tests/testthat/test-pow_search.R @@ -2,7 +2,7 @@ context("pow_search") test_that("pow_search returns the correct class", { skip_on_cran() vcr::use_cassette("pow_search", { - one <- pow_search(q = "Quercus") + one <- pow_search(sci_com = "Quercus") }, preserve_exact_body_bytes = TRUE) expect_is(one, "list") @@ -15,8 +15,8 @@ test_that("pow_search returns the correct class", { test_that("pow_search fails well", { skip_on_cran() - expect_error(pow_search(), "\"q\" is missing") - expect_error(pow_search(4), "q must be of class") + expect_error(pow_search(), "\"sci_com\" is missing") + expect_error(pow_search(4), "sci_com must be of class") expect_error(pow_search("foo", "bar"), "limit must be of class") expect_error(pow_search("foo", 1, 5), "cursor must be of class") expect_error(pow_search("foo", 1, "bar", 5), "sort must be of class") diff --git a/tests/testthat/test-tp_search.R b/tests/testthat/test-tp_search.R index 82b80395..2525ce3f 100644 --- a/tests/testthat/test-tp_search.R +++ b/tests/testthat/test-tp_search.R @@ -3,8 +3,8 @@ context("tp_search") test_that("tp_search returns the correct class", { skip_on_cran() # uses secrets vcr::use_cassette("tp_search", { - ttt <- suppressMessages(tp_search(name = 'Poa annua')) - uuu <- suppressMessages(tp_search(name = 'stuff things')) + ttt <- suppressMessages(tp_search(sci = 'Poa annua')) + uuu <- suppressMessages(tp_search(sci = 'stuff things')) }, preserve_exact_body_bytes = TRUE) if ("error" %in% names(ttt)) skip("error in tp_search call - skipping")