Skip to content
This repository has been archived by the owner on May 10, 2022. It is now read-only.

Commit

Permalink
use markdown docs, fix #10 - not really fixed, but as good as we can do
Browse files Browse the repository at this point in the history
related, export a function fro user to get the all dataset
  • Loading branch information
sckott committed Apr 30, 2018
1 parent 3d54d55 commit b39d1ce
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 59 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Authors@R: c(
License: MIT + file LICENSE
URL: https://github.com/ropensci/originr
BugReports: https://github.com/ropensci/originr/issues
Roxygen: list(markdown = TRUE)
Imports:
crul (>= 0.5.2),
jsonlite (>= 1.5),
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Generated by roxygen2: do not edit by hand

export(eol)
export(eol_invasive_data)
export(flora_europaea)
export(gisd)
export(griis)
Expand Down
81 changes: 62 additions & 19 deletions R/eol.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@
#' @param ... curl options passed on to \code{\link[crul]{HttpClient}}
#'
#' @details
#' `eol_invasive_data()` gives you the entire data.frame from
#' the "dataset=all", while `eol()` let's you search on a vector of names
#' against any of the datasets
#'
#' IMPORTANT: note that setting `dataset="all"` will give you surprising results.
#' EOL does not include informaiton on which of the invasive datasets (i.e., gisd100,
#' gisd, isc, daisie, i3n, or mineps) the taxon is found in, and sometimes e.g., if
#' taxon X is in GISD, you might not find it in "all", weird. I don't know
#' why that's happening, but it shouldn't happen.
#'
#' IMPORTANT: When you get a returned NaN for a taxon, that means it's not on
#' the invasive list in question. If the taxon is found, a taxon identifier
#' is returned.
Expand All @@ -27,40 +37,37 @@
#' pull down all data before we can search for your species. Note there is no
#' parameter in this API method for searching by taxon name.
#'
#' This function is vectorized, so you can pass a single name or a vector
#' `eol()` is vectorized, so you can pass a single name or a vector
#' of names.
#'
#' It's possible to return JSON or XML with the EOL API. However, this function
#' only returns JSON for now.
#' only returns JSON.
#'
#' Options for the dataset parameter are
#' \itemize{
#' \item all - All datasets
#' \item gisd100 - 100 of the World's Worst Invasive Alien Species
#'
#' - all - All datasets
#' - gisd100 - 100 of the World's Worst Invasive Alien Species
#' (Global Invasive Species Database) http://eol.org/collections/54500
#' \item gisd - Global Invasive Species Database 2013
#' - gisd - Global Invasive Species Database 2013
#' http://eol.org/collections/54983
#' \item isc - Centre for Agriculture and Biosciences International Invasive
#' - isc - Centre for Agriculture and Biosciences International Invasive
#' Species Compendium (ISC) http://eol.org/collections/55180
#' \item daisie - Delivering Alien Invasive Species Inventories for Europe
#' - daisie - Delivering Alien Invasive Species Inventories for Europe
#' (DAISIE) Species List http://eol.org/collections/55179
#' \item i3n - IABIN Invasives Information Network (I3N) Species
#' - i3n - IABIN Invasives Information Network (I3N) Species
#' http://eol.org/collections/55176
#' \item mineps - Marine Invaders of the NE Pacific
#' - mineps - Marine Invaders of the NE Pacific
#' Species http://eol.org/collections/55331
#' }
#'
#' Datasets are not updated that often. Here's last updated dates for some of
#' the datasets as of 2014-08-25
#'
#' \itemize{
#' \item gisd100 updated 6 mos ago
#' \item gisd updated 1 yr ago
#' \item isc updated 1 yr ago
#' \item daisie updated 1 yr ago
#' \item i3n updated 1 yr ago
#' \item mineps updated 1 yr ago
#' }
#' - gisd100 updated 6 mos ago
#' - gisd updated 1 yr ago
#' - isc updated 1 yr ago
#' - daisie updated 1 yr ago
#' - i3n updated 1 yr ago
#' - mineps updated 1 yr ago
#'
#' @return A list of data.frame's/strings with results, with each element
#' named by the input elements to the name parameter.
Expand Down Expand Up @@ -163,3 +170,39 @@ getmatches <- function(x, y, z) {
z[matched, ]
}
}

#' @export
#' @rdname eol
eol_invasive_data <- function(...) {
args <- orc(list(per_page = 500, filter = 'taxa'))
path <- "/api/collections/1.0/55367.json"
cli <- crul::HttpClient$new(url = 'http://eol.org',
opts = list(...))
tt <- cli$get(path, query = args)
tt$raise_for_status()
res <- jsonlite::fromJSON(tt$parse("UTF-8"), FALSE)
data_init <- res$collection_items
message(sprintf("Getting data for %s names...", res$total_items))

pages_get <- pages_left(res)

if (!is.null(pages_get)) {
out <- list()
for (i in pages_get) {
args <- orc(list(page = i, per_page = 500, filter = 'taxa'))
tt <- cli$get(path, query = args)
tt$raise_for_status()
res <- jsonlite::fromJSON(tt$parse("UTF-8"), FALSE)
out[[i]] <- res$collection_items
}
res2 <- orc(out)
dat_all <- do.call(c, list(data_init, do.call(c, res2)))
dat_all <- lapply(dat_all, "[", c("name", "object_id"))
dat <- todf(dat_all)
} else {
dat_all <- lapply(data_init, "[", c("name","object_id"))
dat <- todf(dat_all)
}
return(dat)
}

58 changes: 35 additions & 23 deletions man/eol.Rd

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

18 changes: 9 additions & 9 deletions man/flora_europaea.Rd

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

2 changes: 1 addition & 1 deletion man/gisd.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/griis.Rd

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

10 changes: 5 additions & 5 deletions man/originr-package.Rd

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

0 comments on commit b39d1ce

Please sign in to comment.