Skip to content

Commit

Permalink
fix various urls - make coral fxns defunct fix #124
Browse files Browse the repository at this point in the history
  • Loading branch information
sckott committed Aug 26, 2020
1 parent 2fca80c commit 8d08d4c
Show file tree
Hide file tree
Showing 22 changed files with 90 additions and 327 deletions.
7 changes: 3 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
Package: traits
Title: Species Trait Data from Around the Web
Description: Species trait data from many different sources, including
sequence data from 'NCBI', plant trait data from 'BETYdb', plant data
from the USDA plants database, data from 'EOL' 'Traitbank',
Coral traits data (<https://coraltraits.org>), 'Birdlife' International,
and more.
sequence data from 'NCBI' (<https://www.ncbi.nlm.nih.gov/>),
plant trait data from 'BETYdb', data from 'EOL' 'Traitbank',
'Birdlife' International, and more.
Version: 0.5.0
Authors@R: c(
person("Scott", "Chamberlain", role = c("aut", "cre"),
Expand Down
6 changes: 3 additions & 3 deletions R/birdlife.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
#'
#' @export
#' @param id A single IUCN species ID
#' @return a \code{data.frame} with level 1 and level 2 habitat classes, as
#' @return a `data.frame` with level 1 and level 2 habitat classes, as
#' well as importance ratings and occurrence type (e.g. breeding or
#' non-breeding). The habitat classification scheme is described
#' at \url{http://bit.ly/1e6gKBr}
#' at https://www.iucnredlist.org/resources/classification-schemes
#' @author David J. Harris \email{harry491@@gmail.com}
#' @family birdlife
#' @examples \dontrun{
Expand All @@ -31,7 +31,7 @@ birdlife_habitat <- function(id) {
#'
#' @export
#' @inheritParams birdlife_habitat
#' @return a \code{data.frame} with the species ID and two levels of threat
#' @return a `data.frame` with the species ID and two levels of threat
#' descriptions, plus stresses, timing, scope, severity, and impact associated
#' with each stressor.
#' @author David J. Harris \email{harry491@@gmail.com}
Expand Down
114 changes: 24 additions & 90 deletions R/coral.R
Original file line number Diff line number Diff line change
@@ -1,111 +1,45 @@
#' Search for coral data on coraltraits.org
#'
#' @name coral
#' @param taxon A taxon id
#' @param trait A trait id
#' @param location A location id
#' @param methodology A methodology id
#' @param resource A resource id
#' @param taxonomy logical; Include contextual data. Default: `FALSE`
#' @param contextual logical; Include contextual data. Default: `TRUE`
#' @param global logical; Include contextual data. Default: `FALSE`
#' @param ... Curl options passed on to [crul::verb-GET]
#'
#' DEFUNCT: As far as we can tell the coraltraits.org API is down
#' for good
#'
#' @name coral-defunct
#' @keywords internal
#' @param ... ignored
#' @references https://coraltraits.org/
#' @author Scott Chamberlain \email{myrmecocystus@@gmail.com}
#' @examples \dontrun{
#' # Get the species and their Ids
#' head( coral_species() )
#'
#' # Get data by taxon
#' coral_taxa(8)
#'
#' # Get data by trait
#' coral_traits(3)
#'
#' # Get data by methodology
#' coral_methodologies(2)
#'
#' # Get data by location
#' coral_locations(132)
#'
#' # Get data by resource
#' coral_resources(9)
#'
#' # curl options
#' coral_taxa(8, verbose=TRUE)
#' }

#' @export
#' @rdname coral
coral_taxa <- function(taxon, taxonomy = FALSE, contextual = TRUE,
global = FALSE, ...) {
args <- list(taxonomy = lsw(taxonomy), contextual = lsw(contextual),
global = lsw(global))
coral_GET(coral_url("species", taxon), args, ...)
#' @rdname coral-defunct
coral_taxa <- function(...) {
.Defunct(msg = "the coraltraits.org API is down for good")
}

#' @export
#' @rdname coral
coral_traits <- function(trait, taxonomy = FALSE, contextual = TRUE,
global = FALSE, ...) {
args <- list(taxonomy = lsw(taxonomy), contextual = lsw(contextual),
global = lsw(global))
coral_GET(coral_url("traits", trait), args, ...)
#' @rdname coral-defunct
coral_traits <- function(...) {
.Defunct(msg = "the coraltraits.org API is down for good")
}

#' @export
#' @rdname coral
coral_locations <- function(location, taxonomy = FALSE, contextual = TRUE,
global = FALSE, ...) {
args <- list(taxonomy = lsw(taxonomy), contextual = lsw(contextual),
global = lsw(global))
coral_GET(coral_url("locations", location), args, ...)
#' @rdname coral-defunct
coral_locations <- function(...) {
.Defunct(msg = "the coraltraits.org API is down for good")
}

#' @export
#' @rdname coral
coral_methodologies <- function(methodology, taxonomy = FALSE,
contextual = TRUE, global = FALSE, ...) {
args <- list(taxonomy = lsw(taxonomy), contextual = lsw(contextual),
global = lsw(global))
coral_GET(coral_url("methodologies", methodology), args, ...)
#' @rdname coral-defunct
coral_methodologies <- function(...) {
.Defunct(msg = "the coraltraits.org API is down for good")
}

#' @export
#' @rdname coral
coral_resources <- function(resource, taxonomy = FALSE, contextual = TRUE,
global = FALSE, ...) {
args <- list(taxonomy = lsw(taxonomy), contextual = lsw(contextual),
global = lsw(global))
coral_GET(coral_url("resources", resource), args, ...)
#' @rdname coral-defunct
coral_resources <- function(...) {
.Defunct(msg = "the coraltraits.org API is down for good")
}

#' @export
#' @rdname coral
#' @rdname coral-defunct
coral_species <- function(...) {
con <- crul::HttpClient$new("https://coraltraits.org/species",
opts = list(...))
res <- con$get(query = list(all="true"))
res$raise_for_status()
html <- xml2::read_html(res$parse("UTF-8"))
ids <- gsub("\n+|\t+|\\s+", "",
xml2::xml_text(xml2::xml_find_all(html,
'//li[@class="list-group-item"]//div[@style="color: lightgrey;"]')))
nms <- xml2::xml_text(
xml2::xml_find_all(html,
'//li[@class="list-group-item"]//div[@class="col-sm-5"]//a'))
tibble::as_tibble(data.frame(name = nms, id = ids, stringsAsFactors = FALSE))
.Defunct(msg = "the coraltraits.org API is down for good")
}

coral_GET <- function(url, args, ...) {
con <- crul::HttpClient$new(url, opts = list(...))
res <- con$get(query = args)
res$raise_for_status()
txt <- res$parse("UTF-8")
tibble::as_tibble(
utils::read.csv(text = txt, header = TRUE, stringsAsFactors = FALSE))
}

coralbase <- function() 'https://coraltraits.org'
coral_url <- function(var, id) paste0(file.path(coralbase(), var, id), ".csv")
lsw <- function(x) if (x) "on" else "off"
8 changes: 7 additions & 1 deletion R/defunct.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#' Defunct functions in traits
#'
#' These functions have been removed. See package `originr`
#' These functions have been removed.
#'
#' - `eol_invasive_`: This function has moved to a new package.
#' See `originr::eol`
Expand All @@ -11,6 +11,12 @@
#' - `is_native`: This function has moved to a new package. See
#' `originr::is_native`
#' - `tr_usda`: the API behind this function is down for good
#' - `coral_locations`: API down for good, as far as I can tell
#' - `coral_methodologies`: API down for good, as far as I can tell
#' - `coral_resources`: API down for good, as far as I can tell
#' - `coral_species`: API down for good, as far as I can tell
#' - `coral_taxa`: API down for good, as far as I can tell
#' - `coral_traits`: API down for good, as far as I can tell
#'
#' @name traits-defunct
NULL
2 changes: 1 addition & 1 deletion R/ncbi_byid.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#' @details If bad ids are included with good ones, the bad ones are
#' silently dropped. If all ids are bad you'll get a stop with error message.
#' @seealso [ncbi_searcher()], ncbi_byname()]
#' @author Scott Chamberlain \email{myrmecocystus@@gmail.com}, Rupert Collins
#' @author Scott Chamberlain, Rupert Collins
#' @examples \dontrun{
#' # A single gene
#' ncbi_byid(ids="360040093")
Expand Down
2 changes: 1 addition & 1 deletion R/ncbi_byname.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#' picking the longest available for the given gene.
#' @return data.frame
#' @seealso [ncbi_searcher()], [ncbi_byid()]
#' @author Scott Chamberlain \email{myrmecocystus@@gmail.com}
#' @author Scott Chamberlain
#' @examples \dontrun{
#' # A single species
#' ncbi_byname(taxa="Acipenser brevirostrum")
Expand Down
3 changes: 1 addition & 2 deletions R/ncbi_searcher.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
#' @return \code{data.frame} of results if a single input is given. A list of
#' \code{data.frame}s if multiple inputs are given.
#' @seealso \code{\link{ncbi_byid}}, \code{\link{ncbi_byname}}
#' @author Scott Chamberlain \email{myrmecocystus@@gmail.com}, Zachary Foster
#' \email{zacharyfoster1989@@gmail.com}
#' @author Scott Chamberlain, Zachary Foster \email{zacharyfoster1989@@gmail.com}
#' @section Authentication:
#' NCBI rate limits requests. If you set an API key you have a higher rate limit.
#' Set your API key like `Sys.setenv(ENTREZ_KEY="yourkey")` or you can use
Expand Down
2 changes: 1 addition & 1 deletion R/taxa_search.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#' maybe in the future
#' @param ... Curl options passed on to \code{\link[httr]{GET}}
#' @return A \code{data.frame}
#' @author Scott Chamberlain \email{myrmecocystus@@gmail.com}
#' @author Scott Chamberlain
#' @examples \dontrun{
#' taxa_search("Poa annua", db = "ncbi")
#' }
Expand Down
14 changes: 1 addition & 13 deletions R/traits-package.r
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#' - National Center for Biotechnology Information - NCBI
#' http://www.ncbi.nlm.nih.gov/ - `ncbi_`
#' - Encyclopedia of Life Traitbank - `traitbank_`
#' - Coral Traits Database https://coraltraits.org/ - `coral_`
#' - Birdlife International https://www.birdlife.org/ -
#' `birdlife_`
#' - LEDA Traitbase http://www.leda-traitbase.org/LEDAportal/index.jsp -
Expand All @@ -17,17 +16,6 @@
#'
#' See also [traits-defunct]
#'
#' @examples \dontrun{
#' library("traits")
#'
#' ## Search the Coral database
#' ## Get the species list and their ids
#' coral_species()
#'
#' ## Get data by taxon
#' coral_taxa(80)
#' }
#'
#' @importFrom httr GET POST content stop_for_status warn_for_status
#' authenticate
#' @importFrom crul HttpClient
Expand All @@ -42,7 +30,7 @@
#' @name traits-package
#' @aliases traits
#' @docType package
#' @author Scott Chamberlain \email{myrmecocystus@@gmail.com}
#' @author Scott Chamberlain
#' @author Ignasi Bartomeus
#' @author Zachary Foster
#' @author David LeBauer
Expand Down
5 changes: 0 additions & 5 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,6 @@ Included in `traits` with the associated function prefix or function name:
<td style="text-align:left;"><code>traitbank_</code></td>
<td style="text-align:left;">https://github.com/EOL/eol_website/blob/master/doc/api.md</td>
</tr>
<tr>
<td style="text-align:left;">Coral Traits Database</td>
<td style="text-align:left;"><code>coral_</code></td>
<td style="text-align:left;">https://coraltraits.org/</td>
</tr>
<tr>
<td style="text-align:left;">Birdlife International</td>
<td style="text-align:left;"><code>birdlife_</code></td>
Expand Down
5 changes: 0 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,6 @@ Included in `traits` with the associated function prefix or function name:
<td style="text-align:left;"><code>traitbank_</code></td>
<td style="text-align:left;">https://github.com/EOL/eol_website/blob/master/doc/api.md</td>
</tr>
<tr>
<td style="text-align:left;">Coral Traits Database</td>
<td style="text-align:left;"><code>coral_</code></td>
<td style="text-align:left;">https://coraltraits.org/</td>
</tr>
<tr>
<td style="text-align:left;">Birdlife International</td>
<td style="text-align:left;"><code>birdlife_</code></td>
Expand Down
2 changes: 1 addition & 1 deletion man/birdlife_habitat.Rd

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

35 changes: 35 additions & 0 deletions man/coral-defunct.Rd

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

Loading

0 comments on commit 8d08d4c

Please sign in to comment.