Skip to content

Commit

Permalink
#126 taxonomy fxn added
Browse files Browse the repository at this point in the history
  • Loading branch information
sckott committed Jul 12, 2017
1 parent 4003c95 commit 86c0d8b
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 0 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export(speed)
export(stocks)
export(swimming)
export(synonyms)
export(taxonomy)
export(validate_names)
importFrom(dplyr,"%>%")
importFrom(dplyr,as_data_frame)
Expand Down
34 changes: 34 additions & 0 deletions R/taxonomy.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
taxendpt <- endpoint("taxa")

#' Taxonomy
#'
#' @export
#' @param genus (character) genus name. optional
#' @param species (character) species name. optional
#' @param limit The maximum number of matches from a single API call (e.g.
#' per species). Function will warn if this needs to be increased, otherwise
#' can be left as is.
#' @param server base URL to the FishBase API (by default). For SeaLifeBase,
#' use https://fishbase.ropensci.org/sealifebase
#' @param ... additional arguments to httr::GET
#' @examples
#' taxonomy(genus = "Oreochromis", species = "amphimelas")
#' taxonomy(genus = "Oreochromis")
#' taxonomy(species = "amphimelas")
#'
#' taxonomy(genus = "Abrocoma",
#' server = "https://fishbase.ropensci.org/sealifebase")
taxonomy <- function(genus = NULL, species = NULL, limit = 200,
server = getOption("FISHBASE_API", FISHBASE_API), ...) {

taxendpt(query = list(Genus = genus, Species = species), limit = limit,
server = server, ...)
}


# taxonomy <- function(genus = NULL, species = NULL, limit = 200,
# server = NULL, ...) {
#
# taxendpt(query = list(Genus = genus, Species = species), limit = limit,
# server = server, ...)
# }
33 changes: 33 additions & 0 deletions man/taxonomy.Rd

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

14 changes: 14 additions & 0 deletions tests/testthat/test_taxonomy.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
context("taxonomy")

test_that('returns a data.frame with correct sciname', {
needs_api()

aa <- suppressWarnings(taxonomy("Oreochromis", "amphimelas"))
expect_is(aa, "data.frame")
expect_equal(aa$sciname, "Oreochromis amphimelas")
expect_equal(NROW(aa), 1)

bb <- suppressWarnings(taxonomy("Oreochromis"))
expect_is(bb, "data.frame")
expect_gt(NROW(bb), 10)
})

0 comments on commit 86c0d8b

Please sign in to comment.