Skip to content

Commit

Permalink
Fuzzy filter (#56)
Browse files Browse the repository at this point in the history
* export name_contains and starts_with

* include helper fns around fuzzy_filter

* update docs
  • Loading branch information
cboettig committed May 15, 2019
1 parent 4712481 commit f58016d
Show file tree
Hide file tree
Showing 11 changed files with 276 additions and 39 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Expand Up @@ -20,3 +20,4 @@ pkgdown
paper
^ISSUES\.md$
drafts
^renv$
5 changes: 5 additions & 0 deletions NAMESPACE
Expand Up @@ -5,11 +5,15 @@ export(by_id)
export(by_name)
export(by_rank)
export(clean_names)
export(common_contains)
export(common_starts_with)
export(filter_by)
export(fuzzy_filter)
export(get_ids)
export(get_names)
export(mutate_db)
export(name_contains)
export(name_starts_with)
export(synonyms)
export(taxa_tbl)
export(td_connect)
Expand All @@ -21,6 +25,7 @@ importFrom(DBI,dbDisconnect)
importFrom(DBI,dbFetch)
importFrom(DBI,dbGetQuery)
importFrom(DBI,dbIsValid)
importFrom(DBI,dbListTables)
importFrom(DBI,dbSendQuery)
importFrom(DBI,dbWriteTable)
importFrom(MonetDBLite,MonetDBLite)
Expand Down
89 changes: 86 additions & 3 deletions R/fuzzy_filter.R
Expand Up @@ -96,9 +96,22 @@ filter_like <- function(db_tbl, input, pattern){
## Consider creating functions that are explicitly named to create more semantic
## code, rather than relying on setting the behavior in the `by` and `match`
## arguments to `fuzzy_filter`, e.g. :

#' return all taxa in which scientific name contains the text provided
#'
#' @export
#' @examples
#' \donttest{
#' \dontshow{
#' ## All examples use a temporary directory
#' Sys.setenv(TAXADB_HOME=tempdir())
#' }
#' name_contains("Homo ")
#' }
#' @inheritParams fuzzy_filter
name_contains <- function(name,
provider,
db = td_connect,
provider = "itis",
db = td_connect(),
ignore_case = TRUE){

fuzzy_filter(name,
Expand All @@ -109,9 +122,22 @@ name_contains <- function(name,
ignore_case = ignore_case)
}


#' scientific name starts with
#'
#' @examples
#' \donttest{
#' \dontshow{
#' ## All examples use a temporary directory
#' Sys.setenv(TAXADB_HOME=tempdir())
#' }
#' name_contains("Homo ")
#' }
#' @inheritParams fuzzy_filter
#' @export
name_starts_with <- function(name,
provider,
db = td_connect,
db = td_connect(),
ignore_case = TRUE){

fuzzy_filter(name,
Expand All @@ -124,3 +150,60 @@ name_starts_with <- function(name,



#' common name starts with
#'
#' @examples
#' \donttest{
#' \dontshow{
#' ## All examples use a temporary directory
#' Sys.setenv(TAXADB_HOME=tempdir())
#' }
#' common_starts_with("monkey")
#' }
#' @inheritParams fuzzy_filter
#' @export
common_starts_with <- function(name,
provider = "itis",
db = td_connect(),
ignore_case = TRUE){

fuzzy_filter(name,
by = "vernacularName",
provider = provider,
match = "starts_with",
db = db,
ignore_case = ignore_case)
}


#' common name starts with
#'
#' @examples
#' \donttest{
#' \dontshow{
#' ## All examples use a temporary directory
#' Sys.setenv(TAXADB_HOME=tempdir())
#' }
#' common_contains("monkey")
#' }
#' @inheritParams fuzzy_filter
#' @export
common_contains <- function(name,
provider = "itis",
db = td_connect(),
ignore_case = TRUE){

fuzzy_filter(name,
by = "vernacularName",
provider = provider,
match = "contains",
db = db,
ignore_case = ignore_case)
}







2 changes: 1 addition & 1 deletion R/td_create.R
Expand Up @@ -29,7 +29,7 @@
#' @return path where database has been installed (invisibly)
#' @export
#' @importFrom utils download.file
#' @importFrom DBI dbConnect dbDisconnect
#' @importFrom DBI dbConnect dbDisconnect dbListTables
#' @importFrom arkdb unark streamable_readr_tsv
#' @importFrom MonetDBLite MonetDBLite
#' @importFrom readr cols
Expand Down
32 changes: 32 additions & 0 deletions man/common_contains.Rd

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

32 changes: 32 additions & 0 deletions man/common_starts_with.Rd

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

32 changes: 32 additions & 0 deletions man/name_contains.Rd

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

31 changes: 31 additions & 0 deletions man/name_starts_with.Rd

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

0 comments on commit f58016d

Please sign in to comment.