Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
sckott committed Jan 22, 2016
0 parents commit 42428c2
Show file tree
Hide file tree
Showing 43 changed files with 1,188 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
^.*\.Rproj$
^\.Rproj\.user$
^CONDUCT\.md$
README.Rmd
.travis.yml
appveyor.yml
cran-comments.md
NEWS.md
man-roxygen
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.Rproj.user
.Rhistory
.RData
oldtravis.yml

5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
language: r
notifications:
email:
on_success: change
on_failure: change
25 changes: 25 additions & 0 deletions CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Contributor Code of Conduct

As contributors and maintainers of this project, we pledge to respect all people who
contribute through reporting issues, posting feature requests, updating documentation,
submitting pull requests or patches, and other activities.

We are committed to making participation in this project a harassment-free experience for
everyone, regardless of level of experience, gender, gender identity and expression,
sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.

Examples of unacceptable behavior by participants include the use of sexual language or
imagery, derogatory comments or personal attacks, trolling, public or private harassment,
insults, or other unprofessional conduct.

Project maintainers have the right and responsibility to remove, edit, or reject comments,
commits, code, wiki edits, issues, and other contributions that are not aligned to this
Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed
from the project team.

Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by
opening an issue or contacting one or more of the project maintainers.

This Code of Conduct is adapted from the Contributor Covenant
(http:contributor-covenant.org), version 1.0.0, available at
http://contributor-covenant.org/version/1/0/0/
17 changes: 17 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Package: rredlist
Type: Package
Title: IUCN Red List Client
Description: IUCN Red List client. Functions for fetching data and stuff.
Version: 0.0.4.9300
Authors@R: c(person("Scott", "Chamberlain", role = c("aut", "cre"),
email = "[email protected]"))
License: MIT + file LICENSE
URL: https://github.com/ropenscilabs/rredlist
BugReports: https://github.com/ropenscilabs/rredlist/issues
LazyData: TRUE
Imports:
httr,
jsonlite
Suggests:
testthat
RoxygenNote: 5.0.1
2 changes: 2 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
YEAR: 2015
COPYRIGHT HOLDER: Scott Chamberlain
32 changes: 32 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Generated by roxygen2: do not edit by hand

export(rl_common_names)
export(rl_common_names_)
export(rl_countries)
export(rl_countries_)
export(rl_habitats)
export(rl_habitats_)
export(rl_measures)
export(rl_measures_)
export(rl_narrative)
export(rl_narrative_)
export(rl_regions)
export(rl_regions_)
export(rl_search)
export(rl_search_)
export(rl_sp)
export(rl_sp_)
export(rl_sp_category)
export(rl_sp_category_)
export(rl_sp_citation)
export(rl_sp_citation_)
export(rl_sp_count)
export(rl_sp_count_)
export(rl_sp_country)
export(rl_sp_country_)
export(rl_synonyms)
export(rl_synonyms_)
export(rl_threats)
export(rl_threats_)
import(httr)
import(jsonlite)
19 changes: 19 additions & 0 deletions R/rl_common_names.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#' Get species narrative information by taxon name or IUCN id
#'
#' @export
#' @param name (character) Binomial taxonomic name
#' @template all
#' @template info
#' @examples \dontrun{
#' rl_common_names('Loxodonta africana')
#' rl_common_names_('Loxodonta africana')
#' }
rl_common_names <- function(name = NULL, key = NULL, parse = TRUE, ...) {
rl_parse(rr_GET(file.path("species/common_names", name), key, ...), parse)
}

#' @export
#' @rdname rl_common_names
rl_common_names_ <- function(name = NULL, key = NULL, ...) {
rr_GET(file.path("species/common_names", name), key, ...)
}
18 changes: 18 additions & 0 deletions R/rl_countries.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#' Get countries
#'
#' @export
#' @template all
#' @template info
#' @examples \dontrun{
#' rl_countries()
#' rl_countries_()
#' }
rl_countries <- function(key = NULL, parse = FALSE, ...) {
rl_parse(rr_GET("country/list", key, ...), parse)
}

#' @export
#' @rdname rl_countries
rl_countries_ <- function(key = NULL, ...) {
rr_GET("country/list", key, ...)
}
37 changes: 37 additions & 0 deletions R/rl_habitats.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#' Get species habitats by taxon name or IUCN id
#'
#' @export
#' @template commonargs
#' @template all
#' @template info
#' @examples \dontrun{
#' rl_habitats('Fratercula arctica')
#' rl_habitats('Fratercula arctica', region = 'europe')
#' rl_habitats(id = 12392)
#' rl_habitats(id = 22694927, region = 'europe')
#'
#' rl_habitats_('Fratercula arctica')
#' rl_habitats_(id = 12392)
#' }
rl_habitats <- function(name = NULL, id = NULL, region = NULL, key = NULL, parse = TRUE, ...) {
rl_parse(rr_GET(.habitats(name, id, region), key, ...), parse)
}

#' @export
#' @rdname rl_habitats
rl_habitats_ <- function(name = NULL, id = NULL, region = NULL, key = NULL, ...) {
rr_GET(.habitats(name, id, region), key, ...)
}

.habitats <- function(name = NULL, id = NULL, region = NULL) {
stopifnot(xor(!is.null(name), !is.null(id)))
path <- if (!is.null(name)) {
file.path("habitats/species/name", name)
} else {
file.path("habitats/species/id", id)
}
if (!is.null(region)) {
path <- file.path(path, "region", region)
}
path
}
37 changes: 37 additions & 0 deletions R/rl_measures.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#' Get species conservation measures by taxon name or IUCN id
#'
#' @export
#' @template commonargs
#' @template all
#' @template info
#' @examples \dontrun{
#' rl_measures('Fratercula arctica')
#' rl_measures('Fratercula arctica', region = 'europe')
#' rl_measures(id = 12392)
#' rl_measures(id = 22694927, region = 'europe')
#'
#' rl_measures_('Fratercula arctica')
#' rl_measures_(id = 22694927, region = 'europe')
#' }
rl_measures <- function(name = NULL, id = NULL, region = NULL, key = NULL, parse = TRUE, ...) {
rl_parse(rr_GET(.measures(name, id, region), key, ...), parse)
}

#' @export
#' @rdname rl_measures
rl_measures_ <- function(name = NULL, id = NULL, region = NULL, key = NULL, ...) {
rr_GET(.measures(name, id, region), key, ...)
}

.measures <- function(name = NULL, id = NULL, region = NULL) {
stopifnot(xor(!is.null(name), !is.null(id)))
path <- if (!is.null(name)) {
file.path("measures/species/name", name)
} else {
file.path("measures/species/id", id)
}
if (!is.null(region)) {
path <- file.path(path, "region", region)
}
path
}
37 changes: 37 additions & 0 deletions R/rl_narrative.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#' Get species narrative information by taxon name or IUCN id
#'
#' @export
#' @template commonargs
#' @template all
#' @template info
#' @examples \dontrun{
#' rl_narrative('Fratercula arctica')
#' rl_narrative('Fratercula arctica', region = 'europe')
#' rl_narrative(id = 12392)
#' rl_narrative(id = 22694927, region = 'europe')
#'
#' rl_narrative_('Fratercula arctica')
#' rl_narrative_('Fratercula arctica', region = 'europe')
#' }
rl_narrative <- function(name = NULL, id = NULL, region = NULL, key = NULL, parse = TRUE, ...) {
rl_parse(rr_GET(.narrative(name, id, region), key, ...), parse)
}

#' @export
#' @rdname rl_narrative
rl_narrative_ <- function(name = NULL, id = NULL, region = NULL, key = NULL, ...) {
rr_GET(.narrative(name, id, region), key, ...)
}

.narrative <- function(name = NULL, id = NULL, region = NULL) {
stopifnot(xor(!is.null(name), !is.null(id)))
path <- if (!is.null(name)) {
file.path("species/narrative", name)
} else {
file.path("species/narrative/id", id)
}
if (!is.null(region)) {
path <- file.path(path, "region", region)
}
path
}
19 changes: 19 additions & 0 deletions R/rl_regions.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#' Get regions
#'
#' @export
#' @template all
#' @template info
#' @examples \dontrun{
#' rl_regions()
#' rl_regions(parse = FALSE)
#' rl_regions_()
#' }
rl_regions <- function(key = NULL, parse = TRUE, ...) {
rl_parse(rr_GET("region/list", key, ...), parse)
}

#' @export
#' @rdname rl_regions
rl_regions_ <- function(key = NULL, ...) {
rr_GET("region/list", key, ...)
}
38 changes: 38 additions & 0 deletions R/rl_search.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#' Search by taxon name or IUCN id
#'
#' @export
#' @template commonargs
#' @template all
#' @template info
#' @examples \dontrun{
#' rl_search('Fratercula arctica')
#' rl_search('Fratercula arctica', region = 'europe')
#' rl_search(id = 12392)
#' rl_search(id = 22694927, region = 'europe')
#'
#' rl_search('Fratercula arctica', parse = FALSE)
#' rl_search_('Fratercula arctica')
#' rl_search_('Fratercula arctica', region = 'europe')
#' }
rl_search <- function(name = NULL, id = NULL, region = NULL, key = NULL, parse = TRUE, ...) {
rl_parse(rr_GET(.search(name, id, region), key, ...), parse)
}

#' @export
#' @rdname rl_search
rl_search_ <- function(name = NULL, id = NULL, region = NULL, key = NULL, ...) {
rr_GET(.search(name, id, region), key, ...)
}

.search <- function(name = NULL, id = NULL, region = NULL) {
stopifnot(xor(!is.null(name), !is.null(id)))
path <- if (!is.null(name)) {
file.path("species", name)
} else {
file.path("species/id", id)
}
if (!is.null(region)) {
path <- file.path(path, "region", region)
}
path
}
21 changes: 21 additions & 0 deletions R/rl_sp.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#' Get species
#'
#' @export
#' @param page (interger) Page to get. Default: 1
#' @template all
#' @examples \dontrun{
#' rl_sp(page = 1)
#' rl_sp(page = 2)
#' rl_sp(page = 3)
#' rl_sp(page = 3, parse = FALSE)
#' rl_sp_(page = 3)
#' }
rl_sp <- function(page, key = NULL, parse = TRUE, ...) {
rl_parse(rr_GET(file.path("species/page", page), key, ...), parse)
}

#' @export
#' @rdname rl_sp
rl_sp_ <- function(page, key = NULL, ...) {
rr_GET(file.path("species/page", page), key, ...)
}
21 changes: 21 additions & 0 deletions R/rl_sp_category.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#' Get species by category
#'
#' @export
#' @param category (character) 2 letter category code
#' @template all
#' @examples \dontrun{
#' rl_sp_category('VU')
#' rl_sp_category('EN')
#' rl_sp_category('EX')
#' rl_sp_category('EX', parse = FALSE)
#' rl_sp_category_('EX')
#' }
rl_sp_category <- function(category, key = NULL, parse = TRUE, ...) {
rl_parse(rr_GET(file.path("species/category", category), key, ...), parse)
}

#' @export
#' @rdname rl_sp_category
rl_sp_category_ <- function(category, key = NULL, parse = TRUE, ...) {
rr_GET(file.path("species/category", category), key, ...)
}
37 changes: 37 additions & 0 deletions R/rl_sp_citation.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#' Get citations
#'
#' @export
#' @template commonargs
#' @template all
#' @template info
#' @examples \dontrun{
#' rl_sp_citation('Balaena mysticetus')
#' rl_sp_citation('Balaena mysticetus', region = 'europe')
#' rl_sp_citation(id = 12392)
#'
#' rl_sp_citation(id = 2467, region = 'europe')
#' rl_sp_citation(id = 2467, region = 'europe', parse = FALSE)
#' rl_sp_citation_(id = 2467, region = 'europe')
#' }
rl_sp_citation <- function(name = NULL, id = NULL, region = NULL, key = NULL, parse = TRUE, ...) {
rl_parse(rr_GET(.sp_citation(name, id, region), key, ...), parse)
}

#' @export
#' @rdname rl_sp_citation
rl_sp_citation_ <- function(name = NULL, id = NULL, region = NULL, key = NULL, ...) {
rr_GET(.sp_citation(name, id, region), key, ...)
}

.sp_citation <- function(name = NULL, id = NULL, region = NULL) {
stopifnot(xor(!is.null(name), !is.null(id)))
path <- if (!is.null(name)) {
file.path("species/citation", name)
} else {
file.path("species/citation/id", id)
}
if (!is.null(region)) {
path <- file.path(path, "region", region)
}
path
}
Loading

0 comments on commit 42428c2

Please sign in to comment.