Skip to content

Commit

Permalink
change 'stripauthority' to 'canonical'. Fixes #451
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardszoecs committed Aug 19, 2015
1 parent 34ac66d commit c999b20
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
17 changes: 9 additions & 8 deletions R/gnr_resolve.R
Expand Up @@ -13,8 +13,9 @@
#' all supplied names from matches in data sources that have classification
#' tree paths. Names out of determined context are penalized during score
#' calculation.
#' @param stripauthority logical; If FALSE (default), gives back names with
#' taxonomic authorities. If TRUE, strips author names.
#' @param canonical logical; If FALSE (default), gives back names with
#' taxonomic authorities. If TRUE, returns canocial names
#' (without tax. authorities and abbreviations).
#' @param highestscore logical; Return those names with the highest score for
#' each searched name?
#' @param best_match_only (logical) If TRUE, best match only returned.
Expand Down Expand Up @@ -55,13 +56,13 @@
#' # Preferred data source
#' gnr_resolve(names = "Helianthus annuus", preferred_data_sources = c(3,4))
#'
#' # Strip taxonomic authorities - default is stripauthority=FALSE
#' # Return canonical names - default is canonical=FALSE
#' head(gnr_resolve(names = "Helianthus annuus")$results)
#' head(gnr_resolve(names = "Helianthus annuus", stripauthority=TRUE)$results)
#' head(gnr_resolve(names = "Helianthus annuus", canonical=TRUE)$results)
#' }

gnr_resolve <- function(names, data_source_ids = NULL, resolve_once = FALSE,
with_context = FALSE, stripauthority = FALSE, highestscore = TRUE, best_match_only = FALSE,
with_context = FALSE, canonical = FALSE, highestscore = TRUE, best_match_only = FALSE,
preferred_data_sources = NULL, http="get", ...) {

http <- match.arg(http, c("get","post"))
Expand Down Expand Up @@ -138,7 +139,7 @@ gnr_resolve <- function(names, data_source_ids = NULL, resolve_once = FALSE,
data_2$matched_name2 <- as.character(data_2$matched_name2)
out <- data_2[order(data_2$submitted_name), ]

if (stripauthority) {
if (canonical) {
out <- out[ , !names(out) %in% "matched_name"]
} else {
out <- out[ , !names(out) %in% "matched_name2"]
Expand Down Expand Up @@ -169,15 +170,15 @@ gnr_resolve <- function(names, data_source_ids = NULL, resolve_once = FALSE,
data_2_preferred$matched_name2 <- as.character(data_2_preferred$matched_name2)
out_preferred <- data_2_preferred[order(data_2_preferred$submitted_name), ]

if (stripauthority) {
if (canonical) {
out_preferred <- out_preferred[ , !names(out_preferred) %in% "matched_name"]
} else {
out_preferred <- out_preferred[ , !names(out_preferred) %in% "matched_name2"]
}
} else {
out_preferred <- NULL
}
# stripauthority = TRUE, may result into duplicates
# canonical = TRUE, may result into duplicates
out <- unique(out)
list(results = out, preferred = out_preferred, not_known = not_known)
}
Expand Down
11 changes: 6 additions & 5 deletions man/gnr_resolve.Rd
Expand Up @@ -5,7 +5,7 @@
\title{Resolve names using Global Names Resolver.}
\usage{
gnr_resolve(names, data_source_ids = NULL, resolve_once = FALSE,
with_context = FALSE, stripauthority = FALSE, highestscore = TRUE,
with_context = FALSE, canonical = FALSE, highestscore = TRUE,
best_match_only = FALSE, preferred_data_sources = NULL, http = "get",
...)
}
Expand All @@ -25,8 +25,9 @@ all supplied names from matches in data sources that have classification
tree paths. Names out of determined context are penalized during score
calculation.}
\item{stripauthority}{logical; If FALSE (default), gives back names with
taxonomic authorities. If TRUE, strips author names.}
\item{canonical}{logical; If FALSE (default), gives back names with
taxonomic authorities. If TRUE, returns canocial names
(without tax. authorities and abbreviations).}
\item{highestscore}{logical; Return those names with the highest score for
each searched name?}
Expand Down Expand Up @@ -75,9 +76,9 @@ gnr_resolve(names = "Helianthus annuus", best_match_only = TRUE)
# Preferred data source
gnr_resolve(names = "Helianthus annuus", preferred_data_sources = c(3,4))
# Strip taxonomic authorities - default is stripauthority=FALSE
# Return canonical names - default is canonical=FALSE
head(gnr_resolve(names = "Helianthus annuus")$results)
head(gnr_resolve(names = "Helianthus annuus", stripauthority=TRUE)$results)
head(gnr_resolve(names = "Helianthus annuus", canonical=TRUE)$results)
}
}
\author{
Expand Down
6 changes: 3 additions & 3 deletions tests/testthat/test-gnr_resolve.R
Expand Up @@ -25,10 +25,10 @@ test_that("best_match_only works correctly", {
expect_is(b$results, "data.frame")
})

test_that("stripauthority works correctly", {
test_that("canonical works correctly", {
y <- "Helianthus annuus"
w <- gnr_resolve(y, stripauthority = TRUE)
z <- gnr_resolve(y, stripauthority = FALSE)
w <- gnr_resolve(y, canonical = TRUE)
z <- gnr_resolve(y, canonical = FALSE)

expect_is(w, "list")
expect_is(z, "list")
Expand Down

0 comments on commit c999b20

Please sign in to comment.