Skip to content

Instantly share code, notes, and snippets.

@sckott
Created December 15, 2014 16:09
Show Gist options
  • Save sckott/2e188c8ab29f9b588c10 to your computer and use it in GitHub Desktop.
Save sckott/2e188c8ab29f9b588c10 to your computer and use it in GitHub Desktop.

taxize gained the new functions *ping() (e.g., itis_ping()) to allow you to ping each data provider that has a web API. That is, excluding those where we simply scrape data (e.g. IUCN), or download tabular data (The Plant List).

See the new functions:

  • col_ping()
  • itis_ping()
  • eol_ping()
  • ncbi_ping()
  • tropicos_ping()
  • nbn_ping()
  • gbif_ping()
  • ubio_ping()
  • bold_ping()
  • ipni_ping()
  • vascan_ping()

With these functions, by default we simply check if the HTTP status code is 200 (meaning, OK, it's up), return TRUE if it is, and FALSE if not. Instead you can match a certain HTTP status code (e.g, 400), or match content. Matching content is a small API call, then we make sure the content returned is as expected, so if this test returns FALSE, the service may be up, but the content returned is wrong (or has changed).

Installation

Install latest dev version of taxize

devtools::install_github("ropensci/taxize")
library("taxize")

Examples

Is a service up or not?

col_ping()
#> [1] TRUE
itis_ping()
#> [1] TRUE
eol_ping()
#> [1] TRUE
ncbi_ping()
#> [1] TRUE
tropicos_ping()
#> [1] TRUE
nbn_ping()
#> [1] TRUE
gbif_ping()
#> [1] TRUE
ubio_ping()
#> [1] TRUE
bold_ping()
#> [1] TRUE
ipni_ping()
#> [1] TRUE
vascan_ping()
#> [1] TRUE

Does the HTTP code returned match 200? It should

nbn_ping(200)
#> [1] TRUE

It should not match 503, should return FALSE

nbn_ping(503)
#> [1] FALSE

We can ask if the output matches what's expected

nbn_ping("content")
#> [1] TRUE
vascan_ping("content")
#> [1] TRUE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment