Skip to content

Commit

Permalink
authority -> provider (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
cboettig authored Feb 25, 2019
1 parent 0d6e684 commit 63a3762
Show file tree
Hide file tree
Showing 21 changed files with 50 additions and 47 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,6 @@ data/*
taxadb
inst/doc
taxizedb
*.spl
*.tex
paper/manuscript.pdf
6 changes: 3 additions & 3 deletions R/classification.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#' @param species a character vector of species names, typically
#' specified as (`Genus species` or `Genus species epithet`)
#' @param id alternately users can provide a vector of species ids.
#' IDs must be prefixed matching the requested authority. See `id`
#' IDs must be prefixed matching the requested provider. See `id`
#' column returned by most `taxadb` functions for examples.
#' @inheritParams ids
#' @return a data.frame with one row for each requested species,
Expand All @@ -26,12 +26,12 @@
#'
classification <- function(species = NULL,
id = NULL,
authority = KNOWN_AUTHORITIES,
provider = KNOWN_AUTHORITIES,
collect = TRUE,
db = td_connect()){

suppress_msg({
out <- dplyr::right_join(taxa_tbl(authority = authority,
out <- dplyr::right_join(taxa_tbl(provider = provider,
schema = "dwc",
db = db),
null_tibble(id, scientificName = species),
Expand Down
4 changes: 2 additions & 2 deletions R/descendants.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
descendants <- function(name = NULL,
rank = NULL,
id = NULL,
authority = KNOWN_AUTHORITIES,
provider = KNOWN_AUTHORITIES,
collect = TRUE,
db = td_connect()){

Expand All @@ -22,7 +22,7 @@ descendants <- function(name = NULL,
df <- data.frame(setNames(list(name), rank), stringsAsFactors = FALSE)
df$id <- id

taxa <- taxa_tbl(authority = authority,
taxa <- taxa_tbl(provider = provider,
schema = "dwc",
db = db)

Expand Down
12 changes: 6 additions & 6 deletions R/fuzzy.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@


search <- function(name = NULL,
authority = KNOWN_AUTHORITIES,
provider = KNOWN_AUTHORITIES,
match = c("exact", "starts_with", "contains"),
format = c("bare", "prefix", "uri"),
db = td_connect()){
match <- match.arg(match)
switch(match,
exact = get_ids(names = name,
authority = authority,
provider = provider,
format = format,
db = db),
starts_with = fuzzy_ids(name = name,
authority = authority,
provider = provider,
match = match,
format = format,
db = db),
contains = fuzzy_ids(name = name,
authority = authority,
provider = provider,
match = match,
format = format,
db = db),
Expand All @@ -29,7 +29,7 @@ search <- function(name = NULL,

#' @importFrom dplyr bind_rows filter collect mutate
fuzzy_ids <- function(name = NULL,
authority = KNOWN_AUTHORITIES,
provider = KNOWN_AUTHORITIES,
match = c("starts_with", "contains"),
format = c("bare", "prefix", "uri"),
db = td_connect()){
Expand All @@ -44,7 +44,7 @@ fuzzy_ids <- function(name = NULL,
lapply(name_pattern,
function(pattern){

taxa_tbl(authority, "dwc", db) %>%
taxa_tbl(provider, "dwc", db) %>%
dplyr::filter(name %like% pattern) %>%
dplyr::collect() %>%
dplyr::mutate(input_name = gsub("%", "", pattern))
Expand Down
6 changes: 3 additions & 3 deletions R/get_ids.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#' A drop-in replacement for `[taxize::get_ids()]`
#' @param names a list of scientific names (which may
#' include higher-order ranks in most authorities).
#' @param db abbreviation code for the authority. See details.
#' @param db abbreviation code for the provider. See details.
#' @param format Format for the returned: bare identifier, one of
#' - `bare` (e.g. `9606`, default, matching `taxize::get_ids()`),
#' - `prefix` (e.g. `NCBI:9606`), or
Expand All @@ -19,7 +19,7 @@
#' Both include `itis`, `ncbi`, `col`, and `gbif`.
#'
#' Like all taxadb functions, this function will run
#' fastest if a local copy of the authority is installed in advance
#' fastest if a local copy of the provider is installed in advance
#' using `[td_create()]`.
#' @examples \dontrun{
#' get_ids("Homo sapiens")
Expand All @@ -38,7 +38,7 @@ get_ids <- function(names,
# be compatible with common space delimiters
names <- gsub("[_|-|\\.]", " ", names)
df <- ids(name = names,
authority = db,
provider = db,
collect = TRUE,
db = taxadb_db)

Expand Down
14 changes: 7 additions & 7 deletions R/ids.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#' @param name a character vector of species names, e.g. "Homo sapiens"
#' (Most but not all authorities can also return ids for higher-level
#' taxonomic names).
#' @param authority from which authority should the hierachy be returned?
#' @param provider from which provider should the hierachy be returned?
#' Default is 'itis'.
#' @param collect logical, default `TRUE`. Should we return an in-memory
#' data.frame (default, usually the most convenient), or a reference to
Expand All @@ -29,7 +29,7 @@
#' @importFrom rlang !!
#' @importFrom magrittr %>%
ids <- function(name = NULL,
authority = KNOWN_AUTHORITIES,
provider = KNOWN_AUTHORITIES,
collect = TRUE,
db = td_connect()){

Expand All @@ -48,13 +48,13 @@ ids <- function(name = NULL,

## Could be pre-computed to avoid the performance hit here.
db_table <-
taxa_tbl(authority, "dwc", db) %>%
taxa_tbl(provider, "dwc", db) %>%
## Could consider other cleaning
## when run in backend DB, uses the DB's built-in lowercase SQL command:
mutate(input = tolower(scientificName))

## Use right_join, so unmatched names are kept, with NA
## Using right join, names appear in order of authority!
## Using right join, names appear in order of provider!

suppress_msg({ # bc MonetDBLite whines about upper-case characters
out <-
Expand Down Expand Up @@ -86,18 +86,18 @@ ids <- function(name = NULL,

## FIXME abstract this to filter on id / name / generic column?
accepted_name <- function(id = NULL,
authority = KNOWN_AUTHORITIES,
provider = KNOWN_AUTHORITIES,
collect = TRUE,
db = td_connect()){
sort <- TRUE # dummy name
input_table <- dplyr::tibble(taxonID = id, sort = 1:length(id))

## Use right_join, so unmatched names are kept, with NA
## Means names appear in order of authority, so we must arrange
## Means names appear in order of provider, so we must arrange
## after-the-fact to match the query order
out <-
dplyr::right_join(
taxa_tbl(authority, "dwc", db),
taxa_tbl(provider, "dwc", db),
input_table,
by = "taxonID",
copy = TRUE) %>%
Expand Down
4 changes: 2 additions & 2 deletions R/synonyms.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ syn_table <- function(taxon, accepted = "accepted"){
#' @inheritParams ids
#' @export
synonyms <- function(name = NULL,
authority = KNOWN_AUTHORITIES,
provider = KNOWN_AUTHORITIES,
collect = TRUE,
db = td_connect()){
ids(name, authority, collect, db) %>%
ids(name, provider, collect, db) %>%
syn_table()

}
6 changes: 3 additions & 3 deletions R/taxa_tbl.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ KNOWN_AUTHORITIES <- c("itis", "ncbi", "col", "tpl",
#' @inheritParams classification
#' @export
taxa_tbl <- function(
authority = KNOWN_AUTHORITIES,
provider = KNOWN_AUTHORITIES,
schema = "dwc",
db = td_connect()){

authority <- match.arg(authority)
tbl_name <- authority
provider <- match.arg(provider)
tbl_name <- provider
if (is.null(db)) return(quick_db(tbl_name))
if (!has_table(tbl_name, db)) return(quick_db(tbl_name))

Expand Down
2 changes: 1 addition & 1 deletion README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ library(taxadb)
td_create()
```

The default behavior installs only the ITIS database. You can also specify a list of authorities to install, or install every authority using `td_create("all")`.
The default behavior installs only the ITIS database. You can also specify a list of authorities to install, or install every provider using `td_create("all")`.


## Test drive
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ td_create()
```

The default behavior installs only the ITIS database. You can also
specify a list of authorities to install, or install every authority
specify a list of authorities to install, or install every provider
using `td_create("all")`.

## Test drive
Expand Down
6 changes: 3 additions & 3 deletions man/classification.Rd

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

6 changes: 3 additions & 3 deletions man/descendants.Rd

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

4 changes: 2 additions & 2 deletions man/get_ids.Rd

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

4 changes: 2 additions & 2 deletions man/ids.Rd

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

4 changes: 2 additions & 2 deletions man/synonyms.Rd

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

4 changes: 2 additions & 2 deletions man/taxa_tbl.Rd

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

2 changes: 1 addition & 1 deletion tests/testthat/test-all-dbs.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ test_that("we can set up a db and call basic functions", {



df <- taxa_tbl(authority = "col")
df <- taxa_tbl(provider = "col")
chameleons <- df %>% filter(family == "Chamaeleonidae") %>% collect()

df <- descendants(name = "Aves", rank = "class")
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-connections.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ test_that("we can use alternative DBs, such as SQLite", {

## and here we go.
td_create(schema = "hierarchy", db = db)
itis <- taxa_tbl(authority = "itis",
itis <- taxa_tbl(provider = "itis",
schema = "hierarchy",
db = db)
DBI::dbDisconnect(db)
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-fast.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ library(dplyr)

test_that("setup-free calls to basic functions", {

df <- taxa_tbl(authority = "itis", db = NULL)
df <- taxa_tbl(provider = "itis", db = NULL)
chameleons <- filter(df, family == "Chamaeleonidae")

df <- descendants(name = "Aves", rank = "class", db = NULL)
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-taxald.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ test_that("we can set up a db and call basic functions", {
td_create(dbdir = test_db)
db <- td_connect(test_db)

df <- taxa_tbl(authority = "itis",
df <- taxa_tbl(provider = "itis",
db = db)

chameleons <- df %>%
Expand Down
2 changes: 1 addition & 1 deletion vignettes/intro.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ library(taxadb)
td_create()
```

The default behavior installs only the ITIS database. You can also specify a list of authorities to install, or install every authority using `td_create("all")`.
The default behavior installs only the ITIS database. You can also specify a list of authorities to install, or install every provider using `td_create("all")`.


## Test drive
Expand Down

0 comments on commit 63a3762

Please sign in to comment.