worrms/ 0000755 0001762 0000144 00000000000 13147645027 011614 5 ustar ligges users worrms/inst/ 0000755 0001762 0000144 00000000000 13147642434 012570 5 ustar ligges users worrms/inst/doc/ 0000755 0001762 0000144 00000000000 13147642433 013334 5 ustar ligges users worrms/inst/doc/worrms_vignette.html 0000644 0001762 0000144 00000057457 13147642433 017502 0 ustar ligges users
Introduction to the worrms package
Introduction to the worrms package
worrms
is an R client for the World Register of Marine Species.
Install
Stable version from CRAN
install.packages("worrms")
Development version from GitHub
install.packages("devtools")
devtools::install_github("ropensci/worrms")
library("worrms")
Get records
WoRMS 'records' are taxa, not specimen occurrences or something else.
by date
wm_records_date('2016-12-23T05:59:45+00:00')
#> # A tibble: 50 x 25
#> AphiaID url
#> * <int> <chr>
#> 1 894298 http://www.marinespecies.org/aphia.php?p=taxdetails&id=894298
#> 2 894301 http://www.marinespecies.org/aphia.php?p=taxdetails&id=894301
#> 3 894297 http://www.marinespecies.org/aphia.php?p=taxdetails&id=894297
#> 4 894302 http://www.marinespecies.org/aphia.php?p=taxdetails&id=894302
#> 5 894296 http://www.marinespecies.org/aphia.php?p=taxdetails&id=894296
#> 6 894299 http://www.marinespecies.org/aphia.php?p=taxdetails&id=894299
#> 7 894303 http://www.marinespecies.org/aphia.php?p=taxdetails&id=894303
#> 8 915236 http://www.marinespecies.org/aphia.php?p=taxdetails&id=915236
#> 9 906769 http://www.marinespecies.org/aphia.php?p=taxdetails&id=906769
#> 10 909454 http://www.marinespecies.org/aphia.php?p=taxdetails&id=909454
#> # ... with 40 more rows, and 23 more variables: scientificname <chr>,
#> # authority <chr>, status <chr>, unacceptreason <lgl>, rank <chr>,
#> # valid_AphiaID <int>, valid_name <chr>, valid_authority <chr>,
#> # kingdom <chr>, phylum <chr>, class <chr>, order <chr>, family <chr>,
#> # genus <chr>, citation <chr>, lsid <chr>, isMarine <int>,
#> # isBrackish <lgl>, isFreshwater <lgl>, isTerrestrial <lgl>,
#> # isExtinct <int>, match_type <chr>, modified <chr>
by a taxonomic name
wm_records_name(name = 'Platanista gangetica')
#> # A tibble: 3 x 25
#> AphiaID url
#> * <int> <chr>
#> 1 254967 http://www.marinespecies.org/aphia.php?p=taxdetails&id=254967
#> 2 383571 http://www.marinespecies.org/aphia.php?p=taxdetails&id=383571
#> 3 254969 http://www.marinespecies.org/aphia.php?p=taxdetails&id=254969
#> # ... with 23 more variables: scientificname <chr>, authority <chr>,
#> # status <chr>, unacceptreason <lgl>, rank <chr>, valid_AphiaID <int>,
#> # valid_name <chr>, valid_authority <chr>, kingdom <chr>, phylum <chr>,
#> # class <chr>, order <chr>, family <chr>, genus <chr>, citation <chr>,
#> # lsid <chr>, isMarine <int>, isBrackish <lgl>, isFreshwater <int>,
#> # isTerrestrial <int>, isExtinct <lgl>, match_type <chr>, modified <chr>
by many names
wm_records_names(name = c('Platanista gangetica', 'Coryphaena'))
#> [[1]]
#> # A tibble: 1 x 25
#> AphiaID url
#> * <int> <chr>
#> 1 254967 http://www.marinespecies.org/aphia.php?p=taxdetails&id=254967
#> # ... with 23 more variables: scientificname <chr>, authority <chr>,
#> # status <chr>, unacceptreason <lgl>, rank <chr>, valid_AphiaID <int>,
#> # valid_name <chr>, valid_authority <chr>, kingdom <chr>, phylum <chr>,
#> # class <chr>, order <chr>, family <chr>, genus <chr>, citation <chr>,
#> # lsid <chr>, isMarine <lgl>, isBrackish <lgl>, isFreshwater <int>,
#> # isTerrestrial <lgl>, isExtinct <lgl>, match_type <chr>, modified <chr>
#>
#> [[2]]
#> # A tibble: 2 x 25
#> AphiaID url
#> * <int> <chr>
#> 1 125960 http://www.marinespecies.org/aphia.php?p=taxdetails&id=125960
#> 2 843430 <NA>
#> # ... with 23 more variables: scientificname <chr>, authority <chr>,
#> # status <chr>, unacceptreason <chr>, rank <chr>, valid_AphiaID <int>,
#> # valid_name <chr>, valid_authority <chr>, kingdom <chr>, phylum <chr>,
#> # class <chr>, order <chr>, family <chr>, genus <chr>, citation <chr>,
#> # lsid <chr>, isMarine <int>, isBrackish <int>, isFreshwater <int>,
#> # isTerrestrial <lgl>, isExtinct <lgl>, match_type <chr>, modified <chr>
by common name
wm_records_common(name = 'clam')
#> # A tibble: 2 x 25
#> AphiaID url
#> * <int> <chr>
#> 1 141919 http://www.marinespecies.org/aphia.php?p=taxdetails&id=141919
#> 2 141936 http://www.marinespecies.org/aphia.php?p=taxdetails&id=141936
#> # ... with 23 more variables: scientificname <chr>, authority <chr>,
#> # status <chr>, unacceptreason <lgl>, rank <chr>, valid_AphiaID <int>,
#> # valid_name <chr>, valid_authority <chr>, kingdom <chr>, phylum <chr>,
#> # class <chr>, order <chr>, family <chr>, genus <chr>, citation <chr>,
#> # lsid <chr>, isMarine <int>, isBrackish <lgl>, isFreshwater <lgl>,
#> # isTerrestrial <lgl>, isExtinct <lgl>, match_type <chr>, modified <chr>
using the TAXMATCH algorithm
wm_records_taxamatch(name = 'Platanista gangetica')
#> [[1]]
#> # A tibble: 1 x 25
#> AphiaID url
#> * <int> <chr>
#> 1 254967 http://www.marinespecies.org/aphia.php?p=taxdetails&id=254967
#> # ... with 23 more variables: scientificname <chr>, authority <chr>,
#> # status <chr>, unacceptreason <lgl>, rank <chr>, valid_AphiaID <int>,
#> # valid_name <chr>, valid_authority <chr>, kingdom <chr>, phylum <chr>,
#> # class <chr>, order <chr>, family <chr>, genus <chr>, citation <chr>,
#> # lsid <chr>, isMarine <lgl>, isBrackish <lgl>, isFreshwater <int>,
#> # isTerrestrial <lgl>, isExtinct <lgl>, match_type <chr>, modified <chr>
APHIA ID <–> name
wm_name2id(name = "Rhincodon")
#> [1] 105749
wm_id2name(id = 105706)
#> [1] "Rhincodontidae"
Get AphiaID via an external ID
wm_external(id = 1080)
#> [1] 85257
wm_external(id = 105706)
#> [1] 159854
Get vernacular names from an AphiaID
wm_common_id(id = 156806)
#> # A tibble: 2 x 3
#> vernacular language_code language
#> * <chr> <chr> <chr>
#> 1 gilded wedgeclam eng English
#> 2 Turton's wedge clam eng English
Children
Get direct taxonomic children for an AphiaID
wm_classification(id = 105706)
#> # A tibble: 11 x 3
#> AphiaID rank scientificname
#> * <int> <chr> <chr>
#> 1 2 Kingdom Animalia
#> 2 1821 Phylum Chordata
#> 3 146419 Subphylum Vertebrata
#> 4 1828 Superclass Gnathostomata
#> 5 11676 Superclass Pisces
#> 6 10193 Class Elasmobranchii
#> 7 368407 Subclass Neoselachii
#> 8 368408 Infraclass Selachii
#> 9 368410 Superorder Galeomorphi
#> 10 10208 Order Orectolobiformes
#> 11 105706 Family Rhincodontidae
Classification
Get classification for an AphiaID
wm_classification(id = 105706)
#> # A tibble: 11 x 3
#> AphiaID rank scientificname
#> * <int> <chr> <chr>
#> 1 2 Kingdom Animalia
#> 2 1821 Phylum Chordata
#> 3 146419 Subphylum Vertebrata
#> 4 1828 Superclass Gnathostomata
#> 5 11676 Superclass Pisces
#> 6 10193 Class Elasmobranchii
#> 7 368407 Subclass Neoselachii
#> 8 368408 Infraclass Selachii
#> 9 368410 Superorder Galeomorphi
#> 10 10208 Order Orectolobiformes
#> 11 105706 Family Rhincodontidae
Synonyms
Get synonyms for an AphiaID
wm_synonyms(id = 105706)
#> # A tibble: 1 x 25
#> AphiaID url
#> * <int> <chr>
#> 1 148832 http://www.marinespecies.org/aphia.php?p=taxdetails&id=148832
#> # ... with 23 more variables: scientificname <chr>, authority <chr>,
#> # status <chr>, unacceptreason <chr>, rank <chr>, valid_AphiaID <int>,
#> # valid_name <chr>, valid_authority <chr>, kingdom <chr>, phylum <chr>,
#> # class <chr>, order <chr>, family <chr>, genus <lgl>, citation <chr>,
#> # lsid <chr>, isMarine <lgl>, isBrackish <lgl>, isFreshwater <lgl>,
#> # isTerrestrial <lgl>, isExtinct <lgl>, match_type <chr>, modified <chr>
worrms/inst/doc/worrms_vignette.Rmd 0000644 0001762 0000144 00000021274 13147636503 017245 0 ustar ligges users
Introduction to the worrms package
==================================
`worrms` is an R client for the [World Register of Marine Species](http://www.marinespecies.org/).
## Install
Stable version from CRAN
```r
install.packages("worrms")
```
Development version from GitHub
```r
install.packages("devtools")
devtools::install_github("ropensci/worrms")
```
```r
library("worrms")
```
## Get records
WoRMS 'records' are taxa, not specimen occurrences or something else.
by date
```r
wm_records_date('2016-12-23T05:59:45+00:00')
#> # A tibble: 50 x 25
#> AphiaID url
#> *
#> 1 894298 http://www.marinespecies.org/aphia.php?p=taxdetails&id=894298
#> 2 894301 http://www.marinespecies.org/aphia.php?p=taxdetails&id=894301
#> 3 894297 http://www.marinespecies.org/aphia.php?p=taxdetails&id=894297
#> 4 894302 http://www.marinespecies.org/aphia.php?p=taxdetails&id=894302
#> 5 894296 http://www.marinespecies.org/aphia.php?p=taxdetails&id=894296
#> 6 894299 http://www.marinespecies.org/aphia.php?p=taxdetails&id=894299
#> 7 894303 http://www.marinespecies.org/aphia.php?p=taxdetails&id=894303
#> 8 915236 http://www.marinespecies.org/aphia.php?p=taxdetails&id=915236
#> 9 906769 http://www.marinespecies.org/aphia.php?p=taxdetails&id=906769
#> 10 909454 http://www.marinespecies.org/aphia.php?p=taxdetails&id=909454
#> # ... with 40 more rows, and 23 more variables: scientificname ,
#> # authority , status , unacceptreason , rank ,
#> # valid_AphiaID , valid_name , valid_authority ,
#> # kingdom , phylum , class , order , family ,
#> # genus , citation , lsid , isMarine ,
#> # isBrackish , isFreshwater , isTerrestrial ,
#> # isExtinct , match_type , modified
```
by a taxonomic name
```r
wm_records_name(name = 'Platanista gangetica')
#> # A tibble: 3 x 25
#> AphiaID url
#> *
#> 1 254967 http://www.marinespecies.org/aphia.php?p=taxdetails&id=254967
#> 2 383571 http://www.marinespecies.org/aphia.php?p=taxdetails&id=383571
#> 3 254969 http://www.marinespecies.org/aphia.php?p=taxdetails&id=254969
#> # ... with 23 more variables: scientificname , authority ,
#> # status , unacceptreason , rank , valid_AphiaID ,
#> # valid_name , valid_authority , kingdom , phylum ,
#> # class , order , family , genus , citation ,
#> # lsid , isMarine , isBrackish , isFreshwater ,
#> # isTerrestrial , isExtinct , match_type , modified
```
by many names
```r
wm_records_names(name = c('Platanista gangetica', 'Coryphaena'))
#> [[1]]
#> # A tibble: 1 x 25
#> AphiaID url
#> *
#> 1 254967 http://www.marinespecies.org/aphia.php?p=taxdetails&id=254967
#> # ... with 23 more variables: scientificname , authority ,
#> # status , unacceptreason , rank , valid_AphiaID ,
#> # valid_name , valid_authority , kingdom , phylum ,
#> # class , order , family , genus , citation ,
#> # lsid , isMarine , isBrackish , isFreshwater ,
#> # isTerrestrial , isExtinct , match_type , modified
#>
#> [[2]]
#> # A tibble: 2 x 25
#> AphiaID url
#> *
#> 1 125960 http://www.marinespecies.org/aphia.php?p=taxdetails&id=125960
#> 2 843430
#> # ... with 23 more variables: scientificname , authority ,
#> # status , unacceptreason , rank , valid_AphiaID ,
#> # valid_name , valid_authority , kingdom , phylum ,
#> # class , order , family , genus , citation ,
#> # lsid , isMarine , isBrackish , isFreshwater ,
#> # isTerrestrial , isExtinct , match_type , modified
```
by common name
```r
wm_records_common(name = 'clam')
#> # A tibble: 2 x 25
#> AphiaID url
#> *
#> 1 141919 http://www.marinespecies.org/aphia.php?p=taxdetails&id=141919
#> 2 141936 http://www.marinespecies.org/aphia.php?p=taxdetails&id=141936
#> # ... with 23 more variables: scientificname , authority ,
#> # status , unacceptreason , rank , valid_AphiaID ,
#> # valid_name , valid_authority , kingdom , phylum ,
#> # class , order , family , genus , citation ,
#> # lsid , isMarine , isBrackish , isFreshwater ,
#> # isTerrestrial , isExtinct , match_type , modified
```
using the TAXMATCH algorithm
```r
wm_records_taxamatch(name = 'Platanista gangetica')
#> [[1]]
#> # A tibble: 1 x 25
#> AphiaID url
#> *
#> 1 254967 http://www.marinespecies.org/aphia.php?p=taxdetails&id=254967
#> # ... with 23 more variables: scientificname , authority ,
#> # status , unacceptreason , rank , valid_AphiaID ,
#> # valid_name , valid_authority , kingdom , phylum ,
#> # class , order , family , genus , citation ,
#> # lsid , isMarine , isBrackish , isFreshwater ,
#> # isTerrestrial , isExtinct , match_type , modified
```
## APHIA ID <--> name
```r
wm_name2id(name = "Rhincodon")
#> [1] 105749
```
```r
wm_id2name(id = 105706)
#> [1] "Rhincodontidae"
```
## Get AphiaID via an external ID
```r
wm_external(id = 1080)
#> [1] 85257
wm_external(id = 105706)
#> [1] 159854
```
## Get vernacular names from an AphiaID
```r
wm_common_id(id = 156806)
#> # A tibble: 2 x 3
#> vernacular language_code language
#> *
#> 1 gilded wedgeclam eng English
#> 2 Turton's wedge clam eng English
```
## Children
Get direct taxonomic children for an AphiaID
```r
wm_classification(id = 105706)
#> # A tibble: 11 x 3
#> AphiaID rank scientificname
#> *
#> 1 2 Kingdom Animalia
#> 2 1821 Phylum Chordata
#> 3 146419 Subphylum Vertebrata
#> 4 1828 Superclass Gnathostomata
#> 5 11676 Superclass Pisces
#> 6 10193 Class Elasmobranchii
#> 7 368407 Subclass Neoselachii
#> 8 368408 Infraclass Selachii
#> 9 368410 Superorder Galeomorphi
#> 10 10208 Order Orectolobiformes
#> 11 105706 Family Rhincodontidae
```
## Classification
Get classification for an AphiaID
```r
wm_classification(id = 105706)
#> # A tibble: 11 x 3
#> AphiaID rank scientificname
#> *
#> 1 2 Kingdom Animalia
#> 2 1821 Phylum Chordata
#> 3 146419 Subphylum Vertebrata
#> 4 1828 Superclass Gnathostomata
#> 5 11676 Superclass Pisces
#> 6 10193 Class Elasmobranchii
#> 7 368407 Subclass Neoselachii
#> 8 368408 Infraclass Selachii
#> 9 368410 Superorder Galeomorphi
#> 10 10208 Order Orectolobiformes
#> 11 105706 Family Rhincodontidae
```
## Synonyms
Get synonyms for an AphiaID
```r
wm_synonyms(id = 105706)
#> # A tibble: 1 x 25
#> AphiaID url
#> *
#> 1 148832 http://www.marinespecies.org/aphia.php?p=taxdetails&id=148832
#> # ... with 23 more variables: scientificname , authority ,
#> # status , unacceptreason , rank , valid_AphiaID ,
#> # valid_name , valid_authority , kingdom , phylum ,
#> # class , order , family , genus , citation ,
#> # lsid , isMarine , isBrackish , isFreshwater ,
#> # isTerrestrial , isExtinct , match_type , modified
```
worrms/tests/ 0000755 0001762 0000144 00000000000 13147642434 012755 5 ustar ligges users worrms/tests/testthat/ 0000755 0001762 0000144 00000000000 13147642434 014615 5 ustar ligges users worrms/tests/testthat/test-wm_distribution.R 0000644 0001762 0000144 00000002114 13147633205 021131 0 ustar ligges users context("wm_distribution")
test_that("wm_distribution basic usage works", {
skip_on_cran()
aa <- wm_distribution(id = 156806)
expect_is(aa, "tbl_df")
expect_is(aa, "data.frame")
expect_gt(NROW(aa), 1)
})
test_that("wm_distribution fails well", {
skip_on_cran()
expect_error(wm_distribution(), "argument \"id\" is missing")
expect_error(wm_distribution("asdfafasdfs"), "id must be of class")
expect_error(wm_distribution(44444), "\\(204\\) No Content")
})
context("wm_distribution_ - plural")
test_that("wm_distribution_ basic usage works", {
skip_on_cran()
aa <- wm_distribution_(id = 156806)
expect_is(aa, "tbl_df")
expect_is(aa, "data.frame")
expect_gt(NROW(aa), 1)
bb <- wm_distribution_(id = c(156806, 126436))
expect_is(aa, "tbl_df")
expect_is(aa, "data.frame")
expect_gt(NROW(bb), NROW(aa))
})
test_that("wm_distribution_ fails well", {
skip_on_cran()
expect_error(wm_distribution_(), "use only one of")
expect_error(wm_distribution_("asdfafasdfs"), "id must be of class")
expect_error(wm_distribution_(44444), "\\(204\\) No Content")
})
worrms/tests/testthat/test-wm_records_taxamatch.R 0000644 0001762 0000144 00000001357 13027323324 022110 0 ustar ligges users context("wm_records_taxamatch")
test_that("wm_records_taxamatch basic usage works", {
skip_on_cran()
aa <- wm_records_taxamatch(name = 'Platanista gangetica')
expect_is(aa, "list")
expect_equal(length(aa), 1)
expect_is(aa[[1]], "tbl_df")
expect_is(aa[[1]], "data.frame")
expect_equal(NROW(aa[[1]]), 1)
})
test_that("wm_records_taxamatch fails well", {
skip_on_cran()
expect_error(wm_records_taxamatch(), "argument \"name\" is missing")
expect_error(wm_records_taxamatch("asdfafasdfs"), "No Content")
expect_error(wm_records_taxamatch(5),
"name must be of class character")
expect_error(wm_records_taxamatch('Platanista gangetica', marine_only = 5),
"marine_only must be of class logical")
})
worrms/tests/testthat/test-wm_records_names.R 0000644 0001762 0000144 00000002032 13035052410 021222 0 ustar ligges users context("wm_records_names")
test_that("wm_records_names - works", {
skip_on_cran()
aa <- wm_records_names(name = 'Platanista gangetica')
expect_is(aa, "list")
expect_is(aa[[1]], "tbl_df")
expect_is(aa[[1]], "data.frame")
expect_true(all(grepl("Platanista", aa[[1]]$scientificname)))
expect_equal(NROW(aa[[1]]), 1)
})
test_that("wm_records_names - fuzzy parameter", {
skip_on_cran()
aa <- wm_records_names(name = 'Platanista gangetica', fuzzy = TRUE)
expect_is(aa, "list")
expect_is(aa[[1]], "tbl_df")
expect_is(aa[[1]], "data.frame")
expect_true(all(grepl("Platanista", aa[[1]]$scientificname)))
expect_gt(NROW(aa[[1]]), 1)
})
test_that("wm_records_names fails well", {
skip_on_cran()
expect_error(wm_records_names(), "argument \"name\" is missing")
expect_error(wm_records_names(55555), "name must be of class character")
expect_error(wm_records_names("asdfs", "Adf"), "fuzzy must be of class logical")
expect_error(wm_records_names("asdfs", marine_only = 5), "marine_only must be of class logical")
})
worrms/tests/testthat/test-wm_name2id.R 0000644 0001762 0000144 00000002041 13147633205 017730 0 ustar ligges users context("wm_name2id")
test_that("wm_name2id - default usage works", {
skip_on_cran()
aa <- wm_name2id(name = "Rhincodon")
expect_type(aa, "integer")
expect_equal(aa, 105749)
})
test_that("wm_name2id fails well", {
skip_on_cran()
expect_error(wm_name2id(), "argument \"name\" is missing")
expect_error(wm_name2id(44444), "name must be of class")
expect_error(wm_name2id("asdfafasdfs"), "\\(204\\) No Content")
})
context("wm_name2id_ - plural")
test_that("wm_name2id_ - default usage works", {
skip_on_cran()
aa <- wm_name2id_(name = "Rhincodon")
expect_type(aa, "list")
expect_named(aa, "Rhincodon")
bb <- wm_name2id_(name = c("Rhincodon", "Gadus morhua"))
expect_type(bb, "list")
expect_type(bb[[1]], "integer")
expect_named(bb, c("Rhincodon", "Gadus morhua"))
})
test_that("wm_name2id_ fails well", {
skip_on_cran()
expect_error(wm_name2id_(), "argument \"name\" is missing")
expect_error(wm_name2id_(44444), "name must be of class")
expect_error(wm_name2id_("asdfafasdfs"), "\\(204\\) No Content")
})
worrms/tests/testthat/test-wm_id2name.R 0000644 0001762 0000144 00000002033 13147633205 017731 0 ustar ligges users context("wm_id2name")
test_that("wm_id2name - default usage works", {
skip_on_cran()
aa <- wm_id2name(id = 1080)
expect_type(aa, "character")
expect_equal(aa, "Copepoda")
})
test_that("wm_id2name fails well", {
skip_on_cran()
expect_error(wm_id2name(), "argument \"id\" is missing")
expect_error(wm_id2name("asdfafasdfs"), "id must be of class")
expect_error(wm_id2name(44444), "\\(204\\) No Content")
})
context("wm_id2name_ - plural")
test_that("wm_id2name_ - default usage works", {
skip_on_cran()
aa <- wm_id2name_(id = 1080)
expect_type(aa, "list")
expect_type(aa[[1]], "character")
expect_equal(aa[[1]], "Copepoda")
bb <- wm_id2name_(id = c(105706, 126436))
expect_type(bb, "list")
expect_equal(length(bb), 2)
expect_named(bb, c('105706', '126436'))
})
test_that("wm_id2name_ fails well", {
skip_on_cran()
expect_error(wm_id2name_(), "argument \"id\" is missing")
expect_error(wm_id2name_("asdfafasdfs"), "id must be of class")
expect_error(wm_id2name_(44444), "\\(204\\) No Content")
})
worrms/tests/testthat/test-wm_common_id.R 0000644 0001762 0000144 00000002447 13147633205 020367 0 ustar ligges users context("wm_common_id")
test_that("wm_common_id basic usage works", {
skip_on_cran()
aa <- wm_common_id(id = 156806)
expect_is(aa, "tbl_df")
expect_is(aa, "data.frame")
expect_named(aa, c('vernacular', 'language_code', 'language'))
expect_match(aa$vernacular, "clam")
})
test_that("wm_common_id fails well", {
skip_on_cran()
expect_error(wm_common_id(), "argument \"id\" is missing")
expect_error(wm_common_id("asdfafasdfs"), "id must be of class")
expect_error(wm_common_id(44444), "\\(204\\) No Content")
})
context("wm_common_id_ - plural")
test_that("wm_common_id_ basic usage works", {
skip_on_cran()
# singular
aa <- wm_common_id_(id = 156806)
expect_is(aa, "tbl_df")
expect_is(aa, "data.frame")
expect_named(aa, c('id', 'vernacular', 'language_code', 'language'))
expect_match(aa$vernacular, "clam")
# plural
bb <- wm_common_id_(id = c(105706, 156806, 397065))
expect_is(bb, "tbl_df")
expect_is(bb, "data.frame")
expect_named(bb, c('id', 'vernacular', 'language_code', 'language'))
expect_gt(NROW(bb), NROW(aa))
})
test_that("wm_common_id_ fails well", {
skip_on_cran()
expect_error(wm_common_id_(), "use only one of")
expect_error(wm_common_id_("asdfafasdfs"), "id must be of class")
expect_error(wm_common_id_(44444), "\\(204\\) No Content")
})
worrms/tests/testthat/test-wm_external.R 0000644 0001762 0000144 00000002234 13147633205 020237 0 ustar ligges users context("wm_external")
test_that("wm_external - default usage works", {
skip_on_cran()
aa <- wm_external(id = 1080)
expect_type(aa, "integer")
expect_equal(aa, 85257)
})
test_that("wm_external - type: fishbase", {
skip_on_cran()
aa <- wm_external(id = 278468, type = "fishbase")
expect_type(aa, "integer")
expect_equal(aa, 8399)
})
test_that("wm_external fails well", {
skip_on_cran()
expect_error(wm_external(), "argument \"id\" is missing")
expect_error(wm_external("asdfafasdfs"), "id must be of class")
expect_error(wm_external(44444), "\\(204\\) No Content")
})
context("wm_external_ - plural")
test_that("wm_external_ - default usage works", {
skip_on_cran()
aa <- wm_external_(id = 1080)
expect_type(aa, "list")
expect_type(aa[[1]], "integer")
expect_equal(aa[[1]], 85257)
bb <- wm_external_(id = c(1080, 126436))
expect_type(bb, "list")
expect_named(bb, c('1080', '126436'))
})
test_that("wm_external_ fails well", {
skip_on_cran()
expect_error(wm_external_(), "use only one of")
expect_error(wm_external_("asdfafasdfs"), "id must be of class")
expect_error(wm_external_(44444), "\\(204\\) No Content")
})
worrms/tests/testthat/test-wm_records_common.R 0000644 0001762 0000144 00000003346 13147633205 021433 0 ustar ligges users context("wm_records_common")
test_that("wm_records_common - works", {
skip_on_cran()
aa <- wm_records_common(name = 'dolphin')
expect_is(aa, "tbl_df")
expect_is(aa, "data.frame")
expect_true(any(grepl("AphiaID", names(aa))))
expect_equal(aa$kingdom, "Animalia")
expect_equal(aa$genus, "Coryphaena")
})
test_that("wm_records_common - fuzzy parameter works", {
skip_on_cran()
aa <- wm_records_common(name = 'dolphin')
bb <- wm_records_common(name = 'dolphin', fuzzy = TRUE)
expect_is(aa, "tbl_df")
expect_is(aa, "data.frame")
expect_is(bb, "tbl_df")
expect_is(bb, "data.frame")
expect_gt(NROW(bb), NROW(aa))
})
test_that("wm_records_common - offset parameter works", {
skip_on_cran()
aa <- wm_records_common(name = 'dolphin', fuzzy = TRUE)
bb <- wm_records_common(name = 'dolphin', fuzzy = TRUE, offset = 10)
expect_false(identical(aa$AphiaID, bb$AphiaID))
})
test_that("wm_records_common fails well", {
skip_on_cran()
expect_error(wm_records_common(), "argument \"name\" is missing")
expect_error(wm_records_common(55555), "name must be of class character")
expect_error(wm_records_common("asdfafasdfs"), "\\(204\\) No Content")
})
context("wm_records_common_ - plural")
test_that("wm_records_common_ - works", {
skip_on_cran()
bb <- wm_records_common_(name = c('dolphin', 'clam'))
expect_is(bb, "tbl_df")
expect_is(bb, "data.frame")
expect_true("dolphin" %in% bb$id)
expect_true("clam" %in% bb$id)
})
test_that("wm_records_common_ fails well", {
skip_on_cran()
expect_error(wm_records_common_(), "argument \"name\" is missing")
expect_error(wm_records_common_(55555), "name must be of class character")
expect_error(wm_records_common_("asdfafasdfs"), "\\(204\\) No Content")
})
worrms/tests/testthat/test-wm_record.R 0000644 0001762 0000144 00000002100 13147633205 017663 0 ustar ligges users context("wm_record")
test_that("wm_record - default usage works", {
skip_on_cran()
aa <- wm_record(id = 105706)
expect_type(aa, "list")
expect_equal(aa$valid_name, "Rhincodontidae")
expect_equal(aa$valid_AphiaID, 105706)
})
test_that("wm_record fails well", {
skip_on_cran()
expect_error(wm_record(), "argument \"id\" is missing")
expect_error(wm_record("asdfafasdfs"), "id must be of class")
expect_error(wm_record(44444), "\\(204\\) No Content")
})
context("wm_record_ - plural")
test_that("wm_record_ - default usage works", {
skip_on_cran()
aa <- wm_record_(id = 105706)
expect_type(aa, "list")
expect_equal(aa$`105706`$valid_name, "Rhincodontidae")
expect_equal(aa$`105706`$valid_AphiaID, 105706)
bb <- wm_record_(id = c(105706, 126436))
expect_type(bb, "list")
expect_named(bb, c('105706', '126436'))
})
test_that("wm_record_ fails well", {
skip_on_cran()
expect_error(wm_record_(), "use only one of")
expect_error(wm_record_("asdfafasdfs"), "id must be of class")
expect_error(wm_record_(44444), "\\(204\\) No Content")
})
worrms/tests/testthat/test-wm_records_name.R 0000644 0001762 0000144 00000002041 13035052147 021046 0 ustar ligges users context("wm_records_name")
test_that("wm_records_name - works", {
skip_on_cran()
aa <- wm_records_name(name = 'Platanista gangetica')
expect_is(aa, "tbl_df")
expect_is(aa, "data.frame")
expect_true(all(grepl("Platanista", aa$scientificname)))
expect_gt(NROW(aa), 1)
})
test_that("wm_records_name - fuzzy parameter", {
skip_on_cran()
aa <- wm_records_name(name = 'Platanista gangetica', fuzzy = FALSE)
expect_is(aa, "tbl_df")
expect_is(aa, "data.frame")
expect_true(all(grepl("Platanista", aa$scientificname)))
expect_equal(NROW(aa), 1)
})
test_that("wm_records_name fails well", {
skip_on_cran()
expect_error(wm_records_name(), "argument \"name\" is missing")
expect_error(wm_records_name(55555), "name must be of class character")
expect_error(wm_records_name("asdfs", "Adf"), "fuzzy must be of class logical")
expect_error(wm_records_name("asdfs", marine_only = 5), "marine_only must be of class logical")
expect_error(wm_records_name("asdfs", offset = "foobar"), "offset must be of class numeric, integer")
})
worrms/tests/testthat/test-wm_children.R 0000644 0001762 0000144 00000004147 13147633205 020212 0 ustar ligges users context("wm_children")
test_that("wm_children basic usage works", {
skip_on_cran()
aa <- wm_children(id = 105706)
expect_is(aa, "tbl_df")
expect_is(aa, "data.frame")
expect_gt(NROW(aa), 1)
expect_equal(unique(aa$family), "Rhincodontidae")
expect_equal(unique(aa$order), "Orectolobiformes")
expect_equal(unique(aa$class), "Elasmobranchii")
expect_equal(unique(aa$phylum), "Chordata")
expect_equal(unique(aa$kingdom), "Animalia")
})
test_that("wm_children - marine_only usage works", {
skip_on_cran()
expect_is(wm_children(id = 105706, FALSE), "tbl_df")
expect_is(wm_children(id = 105706, TRUE), "tbl_df")
})
test_that("wm_children - offset parameter works", {
skip_on_cran()
off1 <- wm_children(id = 105706, offset = 1)
off2 <- wm_children(id = 105706, offset = 2)
expect_equal(off1$AphiaID[1], 297110)
expect_equal(off2$AphiaID[1], 398065)
})
test_that("wm_children fails well", {
skip_on_cran()
expect_error(wm_children(), "argument \"id\" is missing")
expect_error(wm_children("asdfafasdfs"), "id must be of class")
expect_error(wm_children(44444), "\\(204\\) No Content")
})
## plural methods
context("wm_children_ - plural")
test_that("wm_children_ basic usage works", {
skip_on_cran()
# works for singleton input
aa <- wm_children_(id = 254966)
expect_is(aa, "tbl_df")
expect_is(aa, "data.frame")
expect_gt(NROW(aa), 1)
expect_equal(unique(aa$family), "Platanistidae")
# works for >1 input
bb <- wm_children_(id = c(254966, 343613))
expect_is(bb, "tbl_df")
expect_is(bb, "data.frame")
expect_gt(NROW(bb), NROW(aa))
})
test_that("wm_children_ - 'name' input works", {
skip_on_cran()
aa <- wm_children_(name = c('Platanista', 'Leucophaeus'))
expect_is(aa, "tbl_df")
expect_is(aa, "data.frame")
expect_true(any(grepl('Platanista', aa$scientificname)))
expect_true(any(grepl('Leucophaeus', aa$scientificname)))
})
test_that("wm_children_ fails well", {
skip_on_cran()
expect_error(wm_children_(), "use only one of")
expect_error(wm_children_("asdfafasdfs"), "id must be of class")
expect_error(wm_children_(44444), "\\(204\\) No Content")
})
worrms/tests/testthat/test-wm_classification.R 0000644 0001762 0000144 00000002301 13147633205 021403 0 ustar ligges users context("wm_classification")
test_that("wm_classification works", {
skip_on_cran()
aa <- wm_classification(id = 105706)
expect_is(aa, "tbl_df")
expect_is(aa, "data.frame")
expect_named(aa, c('AphiaID', 'rank', 'scientificname'))
})
test_that("wm_classification fails well", {
skip_on_cran()
expect_error(wm_classification(), "argument \"id\" is missing")
expect_error(wm_classification("asdfafasdfs"), "id must be of class")
bb <- wm_classification(23424234)
expect_equal(NROW(bb), 0)
expect_equal(length(names(bb)), 0)
})
context("wm_classification - plural")
test_that("wm_classification_ works", {
skip_on_cran()
# singular works
aa <- wm_classification_(id = 105706)
expect_is(aa, "tbl_df")
expect_is(aa, "data.frame")
expect_named(aa, c('id', 'AphiaID', 'rank', 'scientificname'))
# many works
bb <- wm_classification_(id = c(254967, 344089))
expect_is(bb, "tbl_df")
expect_is(bb, "data.frame")
expect_named(bb, c('id', 'AphiaID', 'rank', 'scientificname'))
})
test_that("wm_classification_ fails well", {
skip_on_cran()
expect_error(wm_classification_(), "use only one of")
expect_error(wm_classification_("asdfafasdfs"), "id must be of class")
})
worrms/tests/testthat/test-wm_synonyms.R 0000644 0001762 0000144 00000002066 13147633205 020317 0 ustar ligges users context("wm_synonyms")
test_that("wm_synonyms - works", {
skip_on_cran()
aa <- wm_synonyms(id = 105706)
expect_is(aa, "tbl_df")
expect_is(aa, "data.frame")
expect_equal(NROW(aa), 1)
expect_true(any(grepl("scientificname", names(aa))))
expect_true(any(grepl("AphiaID", names(aa))))
expect_true(any(grepl("valid_AphiaID", names(aa))))
expect_true(any(grepl("valid_name", names(aa))))
expect_true(any(grepl("valid_authority", names(aa))))
})
test_that("wm_synonyms fails well", {
skip_on_cran()
expect_error(wm_synonyms(), "argument \"id\" is missing")
expect_error(wm_synonyms(55555), "\\(204\\) No Content")
})
context("wm_synonyms_ - plural")
test_that("wm_synonyms_ - works", {
skip_on_cran()
aa <- wm_synonyms_(id = c(105706, 126436))
expect_is(aa, "tbl_df")
expect_is(aa, "data.frame")
expect_true('105706' %in% aa$id)
expect_true('126436' %in% aa$id)
})
test_that("wm_synonyms_ fails well", {
skip_on_cran()
expect_error(wm_synonyms_(), "use only one of")
expect_error(wm_synonyms_(55555), "\\(204\\) No Content")
})
worrms/tests/testthat/test-wm_record_by_external.R 0000644 0001762 0000144 00000003005 13147633205 022264 0 ustar ligges users context("wm_record_by_external")
test_that("wm_record_by_external - default - by id type tsn", {
skip_on_cran()
# tsn
tsn <- wm_record_by_external(id = 85257)
expect_type(tsn, "list")
expect_equal(tsn$valid_name, "Copepoda")
expect_equal(tsn$valid_AphiaID, 1080)
# ncbi
ncbi <- wm_record_by_external(id = 6830, type = "ncbi")
expect_type(ncbi, "list")
expect_equal(ncbi$valid_name, "Copepoda")
expect_equal(ncbi$valid_AphiaID, 1080)
# they're equivvalent
expect_identical(tsn, ncbi)
# fishbase
fishbase <- wm_record_by_external(id = 8399, type = "fishbase")
expect_type(fishbase, "list")
expect_equal(fishbase$valid_name, "Callorhinchus callorynchus")
expect_equal(fishbase$valid_AphiaID, 278468)
})
test_that("wm_record_by_external fails well", {
skip_on_cran()
expect_error(wm_record_by_external(), "argument \"id\" is missing")
expect_error(wm_record_by_external("asdfafasdfs"), "id must be of class")
})
context("wm_record_by_external_ - plural")
test_that("wm_record_by_external_ - default - by id type tsn", {
skip_on_cran()
# singluar
tsn <- wm_record_by_external_(id = 85257)
expect_type(tsn, "list")
expect_named(tsn, "85257")
# many
bb <- wm_record_by_external_(id = c(85257, 159854))
expect_is(bb, "list")
expect_named(bb, c("85257", "159854"))
})
test_that("wm_record_by_external_ fails well", {
skip_on_cran()
expect_error(wm_record_by_external_(), "use only one of")
expect_error(wm_record_by_external_("asdfafasdfs"), "id must be of class")
})
worrms/tests/testthat/test-wm_records_date.R 0000644 0001762 0000144 00000000766 13147632241 021062 0 ustar ligges users context("wm_records_date")
test_that("wm_records_date - works", {
skip_on_cran()
a_date <- format(Sys.Date() - 1, "%Y-%m-%dT%H:%M:%S+00:00")
aa <- wm_records_date(a_date)
expect_is(aa, "tbl_df")
expect_is(aa, "data.frame")
expect_true(all(grepl("2017", aa$modified)))
})
test_that("wm_records_date fails well", {
skip_on_cran()
expect_error(wm_records_date(), "argument \"start_date\" is missing")
expect_error(wm_records_date(55555), "start_date must be of class character")
})
worrms/tests/testthat/test-wm_sources.R 0000644 0001762 0000144 00000001674 13147633205 020107 0 ustar ligges users context("wm_sources")
test_that("wm_sources - works", {
skip_on_cran()
aa <- wm_sources(id = 105706)
expect_is(aa, "tbl_df")
expect_is(aa, "data.frame")
expect_true(any(grepl("use", names(aa))))
expect_true(any(grepl("reference", names(aa))))
expect_true(any(grepl("page", names(aa))))
expect_true(any(grepl("url", names(aa))))
})
test_that("wm_sources fails well", {
skip_on_cran()
expect_error(wm_sources(), "argument \"id\" is missing")
expect_error(wm_sources(55555), "\\(204\\) No Content")
})
context("wm_sources_ - plural")
test_that("wm_sources_ - works", {
skip_on_cran()
aa <- wm_sources_(id = c(105706, 126436))
expect_is(aa, "tbl_df")
expect_is(aa, "data.frame")
expect_true('105706' %in% aa$id)
expect_true('126436' %in% aa$id)
})
test_that("wm_sources_ fails well", {
skip_on_cran()
expect_error(wm_sources_(), "use only one of")
expect_error(wm_sources_(55555), "\\(204\\) No Content")
})
worrms/tests/test-all.R 0000644 0001762 0000144 00000000051 13027321070 014604 0 ustar ligges users library("testthat")
test_check("worrms")
worrms/NAMESPACE 0000644 0001762 0000144 00000001254 13147633205 013030 0 ustar ligges users # Generated by roxygen2: do not edit by hand
export(wm_children)
export(wm_children_)
export(wm_classification)
export(wm_classification_)
export(wm_common_id)
export(wm_common_id_)
export(wm_distribution)
export(wm_distribution_)
export(wm_external)
export(wm_external_)
export(wm_id2name)
export(wm_id2name_)
export(wm_name2id)
export(wm_name2id_)
export(wm_record)
export(wm_record_)
export(wm_record_by_external)
export(wm_record_by_external_)
export(wm_records_common)
export(wm_records_common_)
export(wm_records_date)
export(wm_records_name)
export(wm_records_names)
export(wm_records_taxamatch)
export(wm_sources)
export(wm_sources_)
export(wm_synonyms)
export(wm_synonyms_)
worrms/NEWS.md 0000644 0001762 0000144 00000001125 13147640051 012701 0 ustar ligges users worrms 0.2.0
============
### NEW FEATURES
* Added additional sister functions to most exported functions in the
package, all with trailing underscore. For example, `wm_children` and
`wm_children_`. These underscore methods take in many inputs, typically
of a AphiaID or a taxonomic or vernacular name. We decided to make
separate functions so that we minimize any disturbance to the existing
package API. (#4) (#6)
## MINOR IMPROVEMENTS
* Moved to using markdown docs (#5)
* All functions now state what they return (#9)
worrms 0.1.0
============
### NEW FEATURES
* Released to CRAN.
worrms/R/ 0000755 0001762 0000144 00000000000 13147642434 012014 5 ustar ligges users worrms/R/wm_records_date.R 0000644 0001762 0000144 00000001641 13147640306 015276 0 ustar ligges users #' Get records by date
#'
#' @export
#' @param start_date (character) start date. required.
#' @param end_date (character) end date. optional
#' @param marine_only (logical) marine only or not. default: `TRUE`
#' @param offset (integer) record to start at. default: 1
#' @template curl
#' @return A tibble/data.frame
#' @examples \dontrun{
#' a_date <- format(Sys.Date() - 1, "%Y-%m-%dT%H:%M:%S+00:00")
#' wm_records_date(a_date)
#' }
wm_records_date <- function(start_date, end_date = NULL, marine_only = TRUE,
offset = 1, ...) {
assert(start_date, c("character", "Date"))
assert(end_date, c("character", "Date"))
assert(marine_only, "logical")
assert(offset, c('numeric', 'integer'))
wm_GET(file.path(wm_base(), "AphiaRecordsByDate"),
query = cc(list(
startdate = start_date, enddate = end_date,
marine_only = as_log(marine_only), offset = offset)), ...)
}
worrms/R/wm_record_by_external.R 0000644 0001762 0000144 00000002264 13147640322 016512 0 ustar ligges users #' Get record by external ID
#'
#' @export
#' @param id (numeric/integer) an AphiaID. For `wm_record_by_external`
#' it's required and must be `length(id) = 1`, for
#' `wm_record_by_external_` it's optional and can be `length(id) >= 1`
#' @param type (character) the type of external id. one of: tsn, bold,
#' dyntaxa, eol, fishbase, iucn, lsid, ncbi, gisd. default: tsn
#' @param name (character) one or more taxonomic names. optional
#' @template curl
#' @template plural
#' @return A named list. When using underscore method, each output is named
#' by the input ID, and can be separated by the list names
#' @examples \dontrun{
#' wm_record_by_external(id = 85257)
#' wm_record_by_external(id = 159854)
#'
#' wm_record_by_external_(id = c(85257, 159854))
#' }
wm_record_by_external <- function(id, type = "tsn", ...) {
assert(id, c("numeric", "integer"))
assert(type, "character")
wm_GET(file.path(wm_base(), "AphiaRecordByExternalID", id),
query = cc(list(type = type)), ...)
}
#' @export
#' @rdname wm_record_by_external
wm_record_by_external_ <- function(id = NULL, name = NULL, type = "tsn", ...) {
id <- id_name(id, name)
run_c(id, wm_record_by_external, type = type, ...)
}
worrms/R/wm_records_common.R 0000644 0001762 0000144 00000002627 13147640315 015656 0 ustar ligges users #' Get records by vernacular name, optional fuzzy matching
#'
#' @export
#' @param name (character) a species common name. required. For
#' `wm_records_common` must be `length(id) = 1`; for `wm_records_common_`
#' can be `length(id) >= 1`
#' @param fuzzy (logical) fuzzy search. default: `FALSE`
#' @param offset (integer) record to start at. default: 1
#' @template curl
#' @template plural
#' @return A tibble/data.frame. when using underscore method, outputs from
#' each input are binded together, but can be split by `id` column
#' @examples \dontrun{
#' wm_records_common(name = 'dolphin')
#' wm_records_common(name = 'clam')
#'
#' wm_records_common_(name = c('dolphin', 'clam'))
#'
#' wm_records_common(name = 'dolphin', fuzzy = TRUE)
#' wm_records_common(name = 'clam', fuzzy = TRUE, offset = 5)
#' }
wm_records_common <- function(name, fuzzy = FALSE, offset = 1,
...) {
assert(name, "character")
assert(fuzzy, "logical")
assert(offset, c('numeric', 'integer'))
if (length(name) > 1) stop("'name' must be of length 1", call. = FALSE)
args <- cc(list(
like = as_log(fuzzy),
offset = offset
))
wm_GET(file.path(wm_base(), "AphiaRecordsByVernacular", name),
query = args, ...)
}
#' @export
#' @rdname wm_records_common
wm_records_common_ <- function(name, fuzzy = FALSE, offset = 1, ...) {
run_bind(name, wm_records_common, fuzzy = fuzzy, offset = offset, ...)
}
worrms/R/wm_synonyms.R 0000644 0001762 0000144 00000001561 13147640262 014541 0 ustar ligges users #' Get synonyms for an AphiaID
#'
#' @export
#' @param id (numeric/integer) an AphiaID. For `wm_synonyms` it's required
#' and must be `length(id) = 1`, for `wm_synonyms_` it's optional and
#' can be `length(id) >= 1`
#' @param name (character) one or more taxonomic names. optional
#' @template curl
#' @template plural
#' @return A tibble/data.frame. when using underscore method, outputs from
#' each input are binded together, but can be split by `id` column
#' @examples \dontrun{
#' wm_synonyms(id = 105706)
#' wm_synonyms_(id = 105706)
#' wm_synonyms_(id = c(105706, 126436))
#' }
wm_synonyms <- function(id, ...) {
assert(id, c("numeric", "integer"))
wm_GET(file.path(wm_base(), "AphiaSynonymsByAphiaID", id), ...)
}
#' @export
#' @rdname wm_synonyms
wm_synonyms_ <- function(id = NULL, name = NULL, ...) {
id <- id_name(id, name)
run_bind(id, wm_synonyms, ...)
}
worrms/R/wm_distribution.R 0000644 0001762 0000144 00000001641 13147640351 015357 0 ustar ligges users #' Get distribution data by AphiaID
#'
#' @export
#' @param id (numeric/integer) an AphiaID. For `wm_distribution` it's
#' required and must be `length(id) = 1`, for `wm_distribution_` it's
#' optional and can be `length(id) >= 1`
#' @param name (character) one or more taxonomic names. optional
#' @template curl
#' @template plural
#' @return A tibble/data.frame. when using underscore method, outputs from
#' each input are binded together, but can be split by `id` column
#' @examples \dontrun{
#' wm_distribution(id = 156806)
#' wm_distribution(id = 126436)
#'
#' wm_distribution_(id = c(156806, 126436))
#' }
wm_distribution <- function(id, ...) {
assert(id, c("numeric", "integer"))
wm_GET(file.path(wm_base(), "AphiaDistributionsByAphiaID", id), ...)
}
#' @export
#' @rdname wm_distribution
wm_distribution_ <- function(id = NULL, name = NULL, ...) {
id <- id_name(id, name)
run_bind(id, wm_distribution, ...)
}
worrms/R/wm_id2name.R 0000644 0001762 0000144 00000001314 13147640340 014152 0 ustar ligges users #' Get taxonomic name for an AphiaID
#'
#' @export
#' @param id (numeric/integer) an AphiaID, required. For `wm_id2name`
#' must be `length(id) = 1`, but for `wm_id2name_` can be
#' `length(id) >= 1`
#' @template curl
#' @template plural
#' @return An character string that is the taxnomic name. When using underscore
#' method, a list, named by the input IDs
#' @examples \dontrun{
#' wm_id2name(id = 105706)
#' wm_id2name_(id = c(105706, 126436))
#' }
wm_id2name <- function(id, ...) {
assert(id, c("numeric", "integer"))
wm_GET(file.path(wm_base(), "AphiaNameByAphiaID", id), ...)
}
#' @export
#' @rdname wm_id2name
wm_id2name_ <- function(id, ...) {
id <- id_name(id, NULL)
run_c(id, wm_id2name, ...)
}
worrms/R/wm_sources.R 0000644 0001762 0000144 00000001641 13147640271 014324 0 ustar ligges users #' Get sources for an AphiaID
#'
#' @export
#' @param id (numeric/integer) an AphiaID. For `wm_sources` it's required
#' and must be `length(id) = 1`, for `wm_sources_` it's optional and
#' can be `length(id) >= 1`
#' @param name (character) one or more taxonomic names. optional
#' @template curl
#' @template plural
#' @return A tibble/data.frame. when using underscore method, outputs from
#' each input are binded together, but can be split by `id` column
#' @examples \dontrun{
#' wm_sources(id = 105706)
#' wm_sources_(id = 105706)
#' wm_sources_(id = c(105706, 126436))
#' wm_sources_(name = c("Rhincodontidae", "Gadus morhua"))
#' }
wm_sources <- function(id, ...) {
assert(id, c("numeric", "integer"))
wm_GET(file.path(wm_base(), "AphiaSourcesByAphiaID", id), ...)
}
#' @export
#' @rdname wm_sources
wm_sources_ <- function(id = NULL, name = NULL, ...) {
id <- id_name(id, name)
run_bind(id, wm_sources, ...)
}
worrms/R/wm_externalid.R 0000644 0001762 0000144 00000002572 13147640345 015006 0 ustar ligges users #' Get an external ID via an AphiaID
#'
#' @export
#' @param id (numeric/integer) an AphiaID. For `wm_external` it's
#' required and must be `length(id) = 1`, for `wm_external_` it's
#' optional and can be `length(id) >= 1`
#' @param type (character) the type of external id. one of: tsn, bold,
#' dyntaxa, eol, fishbase, iucn, lsid, ncbi, gisd. default: tsn
#' @param name (character) one or more taxonomic names. optional
#' @template curl
#' @template plural
#' @return An integer that is the ID. When using underscore method,
#' a list, named by the input IDs
#' @examples \dontrun{
#' # by default, get a TSN (an ITIS code)
#' wm_external(id = 1080)
#'
#' ## get many
#' wm_external_(id = c(1080, 126436))
#'
#' # BOLD code
#' wm_external(id = 278468, type = "bold")
#'
#' # NCBI code
#' wm_external(id = 278468, type = "ncbi")
#'
#' # fishbase code
#' wm_external(id = 278468, type = "fishbase")
#'
#' # curl options
#' library(crul)
#' wm_external(id = 105706, verbose = TRUE)
#' }
wm_external <- function(id, type = "tsn", ...) {
assert(id, c("numeric", "integer"))
assert(type, "character")
as.integer(wm_GET(
file.path(wm_base(), "AphiaExternalIDByAphiaID", id),
query = cc(list(type = type)), ...))
}
#' @export
#' @rdname wm_external
wm_external_ <- function(id = NULL, name = NULL, type = "tsn", ...) {
id <- id_name(id, name)
run_c(id, wm_external, type = type, ...)
}
worrms/R/wm_record.R 0000644 0001762 0000144 00000001504 13147640332 014113 0 ustar ligges users #' Get complete AphiaRecord for an AphiaID
#'
#' @export
#' @param id (numeric/integer) an AphiaID. For `wm_record` it's
#' required and must be `length(id) = 1`, for `wm_record_` it's
#' optional and can be `length(id) >= 1`
#' @param name (character) one or more taxonomic names. optional
#' @template curl
#' @template plural
#' @return A named list. When using underscore method, each output is named
#' by the input ID, and can be separated by the list names
#' @examples \dontrun{
#' wm_record(id = 105706)
#' wm_record_(id = c(105706, 126436))
#' }
wm_record <- function(id, ...) {
assert(id, c("numeric", "integer"))
wm_GET(file.path(wm_base(), "AphiaRecordByAphiaID", id), ...)
}
#' @export
#' @rdname wm_record
wm_record_ <- function(id = NULL, name = NULL, ...) {
id <- id_name(id, name)
run_c(id, wm_record, ...)
}
worrms/R/wm_records_names.R 0000644 0001762 0000144 00000002215 13147640276 015470 0 ustar ligges users #' Get records for onen or more taxonomic name(s)
#'
#' @export
#' @param name (character) start date. required.
#' @param fuzzy (logical) fuzzy search. default: `FALSE`
#' @param marine_only (logical) marine only or not. default: `TRUE`
#' @template curl
#' @note there is no underscore method like other functions in this package
#' as this is the plural version for [wm_records_name()]
#' @return A list of tibble's/data.frame's, one for each of the input names
#' @examples \dontrun{
#' wm_records_names(name = 'Platanista gangetica')
#' wm_records_names(name = 'Platanista gangetica', fuzzy = TRUE)
#' wm_records_names(name = c('Platanista gangetica', 'Coryphaena'))
#' }
wm_records_names <- function(name, fuzzy = FALSE, marine_only = TRUE, ...) {
assert(name, "character")
assert(fuzzy, "logical")
assert(marine_only, "logical")
args <- cc(list(like = as_log(fuzzy), marine_only = as_log(marine_only)))
args <- c(args,
stats::setNames(as.list(name),
rep('scientificnames[]',
length(name))))
wm_GET(file.path(wm_base(), "AphiaRecordsByNames"),
query = args, ...)
}
worrms/R/worrms-package.R 0000644 0001762 0000144 00000001120 13147634117 015052 0 ustar ligges users #' World Register of Marine Species Client
#'
#' @name worrms-package
#' @aliases worrms
#' @docType package
#' @keywords package
#' @author Scott Chamberlain \email{myrmecocystus@@gmail.com}
#'
#' @section Fail behavior:
#' The WoRMS REST API doesn't have sophisticated error messaging, so
#' most errors will result in a `(204) - No Content` or
#' in `(400) - Bad Request`
#'
#' Because WoRMS doesn't do comprehensive error reporting, we do a fair
#' amount of checking user inputs to help prevent errors that will be
#' meaningless to the user. Let us know if we can improve on this.
NULL
worrms/R/wm_records_taxamatch.R 0000644 0001762 0000144 00000002012 13147635777 016344 0 ustar ligges users #' Get records for onen or more taxonomic name(s) using
#' the TAXAMATCH fuzzy matching algorithm
#'
#' @export
#' @param name (character) taxon name. required.
#' @param marine_only (logical) marine only or not. default: `TRUE`
#' @template curl
#' @note there is no underscore method like other functions in this package
#' as this function already accepts many names
#' @return A list of tibble's/data.frame's, one for each of the input names
#' @examples \dontrun{
#' wm_records_taxamatch(name = 'Platanista gangetica')
#' wm_records_taxamatch(name = c('Platanista gangetica', 'Coryphaena'))
#' }
wm_records_taxamatch <- function(name, marine_only = TRUE, ...) {
assert(name, "character")
assert(marine_only, "logical")
args <- cc(list(marine_only = as_log(marine_only)))
args <- c(args,
stats::setNames(as.list(name),
rep('scientificnames[]',
length(name))))
wm_GET(file.path(wm_base(), "AphiaRecordsByMatchNames"),
query = args, ...)
}
worrms/R/wm_children.R 0000644 0001762 0000144 00000002744 13147640367 014444 0 ustar ligges users #' Get children for an AphiaID
#'
#' @export
#' @param id (numeric/integer) an AphiaID. For `wm_children` it's
#' required and must be `length(id) = 1`, for `wm_children_` it's
#' optional and can be `length(id) >= 1`
#' @param marine_only (logical) marine only or not. default: `TRUE`
#' @param offset (integer) record to start at. default: 1
#' @param name (character) one or more taxonomic names. optional
#' @template curl
#' @template plural
#' @return A tibble/data.frame. when using underscore method, outputs from
#' each input are binded together, but can be split by `id` column
#' @examples \dontrun{
#' wm_children(id = 105706)
#' wm_children(id = 105706, FALSE)
#' wm_children(id = 105706, offset = 5)
#'
#' wm_children(254966)
#' wm_children(343613)
#'
#' # plural version, via id or name
#' wm_children_(id = c(254966, 343613))
#' wm_children_(name = c('Platanista', 'Leucophaeus'))
#' }
wm_children <- function(id, marine_only = TRUE, offset = 1, ...) {
assert(id, c("numeric", "integer"))
assert(marine_only, "logical")
assert(offset, c("numeric", "integer"))
wm_GET(file.path(wm_base(), "AphiaChildrenByAphiaID", id),
query = cc(list(marine_only = as_log(marine_only),
offset = offset)), ...)
}
#' @export
#' @rdname wm_children
wm_children_ <- function(id = NULL, name = NULL, marine_only = TRUE,
offset = 1, ...) {
id <- id_name(id, name)
run_bind(id, wm_children, marine_only = marine_only, offset = offset, ...)
}
worrms/R/wm_classification.R 0000644 0001762 0000144 00000003133 13147640362 015633 0 ustar ligges users #' Get classification for an AphiaID
#'
#' @export
#' @param id (numeric/integer) an AphiaID. For `wm_children` it's
#' required and must be `length(id) = 1`, for `wm_children_` it's
#' optional and can be `length(id) >= 1`
#' @param name (character) one or more taxonomic names. optional
#' @template curl
#' @template plural
#' @return A tibble/data.frame. when using underscore method, outputs from
#' each input are binded together, but can be split by `id` column
#' @examples \dontrun{
#' wm_classification(id = 105706)
#' wm_classification(id = 126436)
#'
#' wm_classification(254967)
#' wm_classification(344089)
#'
#' # plural version, via id or name
#' wm_classification_(id = c(254967, 344089))
#' wm_classification_(name = c('Platanista gangetica', 'Leucophaeus scoresbii'))
#' }
wm_classification <- function(id, ...) {
assert(id, c("numeric", "integer"))
res <- wm_GET(file.path(wm_base(), "AphiaClassificationByAphiaID", id), ...)
done <- FALSE
out <- list()
it <- 0
while (!done) {
it <- it + 1
ch <- res$child
if (!is.null(ch)) {
out[[it]] <- ch[!names(ch) %in% "child"]
res <- list(child = ch$child)
} else {
done <- TRUE
}
}
dat <- Filter(function(x) !is.null(x) && length(x) != 0, out)
dat <- do.call("rbind.data.frame", dat)
dat$rank <- as.character(dat$rank)
dat$scientificname <- as.character(dat$scientificname)
if (NROW(dat) == 0) dat <- NULL
tibble::as_tibble(dat)
}
#' @export
#' @rdname wm_classification
wm_classification_ <- function(id = NULL, name = NULL, ...) {
id <- id_name(id, name)
run_bind(id, wm_classification, ...)
}
worrms/R/wm_common_id.R 0000644 0001762 0000144 00000002136 13147640355 014610 0 ustar ligges users #' Get vernacular names from an AphiaID
#'
#' @export
#' @param id (numeric/integer) an AphiaID. For `wm_common_id` it's
#' required and must be `length(id) = 1`, for `wm_common_id_` it's
#' optional and can be `length(id) >= 1`
#' @param name (character) one or more taxonomic names. optional
#' @template curl
#' @template plural
#' @return A tibble/data.frame. when using underscore method, outputs from
#' each input are binded together, but can be split by `id` column
#' @examples \dontrun{
#' wm_common_id(id = 105706)
#' wm_common_id(id = 156806)
#' wm_common_id(id = 397065)
#'
#' wm_common_id_(id = c(105706, 156806, 397065))
#' nms <- c("Rhincodontidae", "Mesodesma deauratum", "Cryptomya californica")
#' wm_common_id_(name = nms)
#' }
wm_common_id <- function(id, ...) {
assert(id, c("numeric", "integer"))
if (length(id) > 1) stop("'id' must be of length 1", call. = FALSE)
wm_GET(file.path(wm_base(), "AphiaVernacularsByAphiaID", id), ...)
}
#' @export
#' @rdname wm_common_id
wm_common_id_ <- function(id = NULL, name = NULL, ...) {
id <- id_name(id, name)
run_bind(id, wm_common_id, ...)
}
worrms/R/wm_records_name.R 0000644 0001762 0000144 00000002517 13147640302 015300 0 ustar ligges users #' Get records by single name, optional fuzzy matching
#'
#' @export
#' @param name (character) a taxonomic name, required.
#' @param fuzzy (logical) fuzzy search. default: `TRUE`
#' @param marine_only (logical) marine only or not. default: `TRUE`
#' @param offset (integer) record to start at. default: 1
#' @template curl
#' @note there is no underscore method like other functions in this package
#' as there is already a plural version: [wm_records_names()]
#' @return A tibble/data.frame
#' @examples \dontrun{
#' wm_records_name(name = 'Platanista gangetica')
#' wm_records_name(name = 'Platanista gangetica', fuzzy = FALSE)
#' wm_records_name(name = 'Platanista gangetica', marine_only = FALSE)
#' wm_records_name(name = 'Platanista', marine_only = FALSE)
#' wm_records_name(name = 'Platanista', marine_only = FALSE, offset = 5)
#' }
wm_records_name <- function(name, fuzzy = TRUE, marine_only = TRUE, offset = 1,
...) {
assert(name, "character")
assert(fuzzy, "logical")
assert(marine_only, "logical")
assert(offset, c('numeric', 'integer'))
if (length(name) > 1) stop("'name' must be of length 1", call. = FALSE)
args <- cc(list(
like = as_log(fuzzy),
marine_only = as_log(marine_only),
offset = offset
))
wm_GET(file.path(wm_base(), "AphiaRecordsByName", name),
query = args, ...)
}
worrms/R/wm_name2id.R 0000644 0001762 0000144 00000001266 13147640335 014164 0 ustar ligges users #' Get AphiaID from a taxonomic name
#'
#' @export
#' @param name (character) a taxonomic name, required. For
#' `wm_name2id` must be `length(id) = 1`, but for `wm_name2id_`
#' can be `length(id) >= 1`
#' @template curl
#' @template plural
#' @return An integer that is the AphiaID. When using underscore method,
#' a list, named by the input names
#' @examples \dontrun{
#' wm_name2id(name = "Rhincodon")
#' wm_name2id_(name = c("Rhincodon", "Gadus morhua"))
#' }
wm_name2id <- function(name, ...) {
assert(name, "character")
wm_GET(file.path(wm_base(), "AphiaIDByName", name), ...)
}
#' @export
#' @rdname wm_name2id
wm_name2id_ <- function(name, ...) {
run_c(name, wm_name2id, ...)
}
worrms/R/zzz.R 0000644 0001762 0000144 00000003610 13147633205 012770 0 ustar ligges users wm_GET <- function(url, query = list(), ...) {
cli <- crul::HttpClient$new(url = url, opts = list(...))
temp <- cli$get(query = query)
temp$raise_for_status()
if (temp$status_code == 204) {
stop(sprintf("(%s) %s", temp$status_code, temp$status_http()$message), call. = FALSE)
}
tmp <- jsonlite::fromJSON(temp$parse("UTF-8"), flatten = TRUE)
if (inherits(tmp, "data.frame")) {
tibble::as_data_frame(tmp)
} else if (inherits(tmp, "list")) {
if (all(sapply(tmp, class) == "data.frame")) {
lapply(tmp, tibble::as_data_frame)
} else {
tmp
}
} else {
tmp
}
}
wm_base <- function() "http://www.marinespecies.org/rest"
cc <- function(x) Filter(Negate(is.null), x)
ccn <- function(x) {
Filter(function(z) !is.null(z) && NROW(z) > 0, x)
}
`%||%` <- function(x, y) if (is.null(x) || length(x) == 0) y else x
as_log <- function(x) {
if (is.null(x)) {
x
} else {
if (x) "true" else "false"
}
}
assert <- function(x, y) {
if (!is.null(x)) {
if (!class(x) %in% y) {
stop(deparse(substitute(x)), " must be of class ",
paste0(y, collapse = ", "), call. = FALSE)
}
}
}
br <- function(x) {
(x <- data.table::setDF(
data.table::rbindlist(x, use.names = TRUE, fill = TRUE, idcol = "id")))
}
run_c <- function(id, fun, ...) {
ccn(stats::setNames(lapply(id, fun, ...), id))
}
run_bind <- function(id, fun, ...) {
tibble::as_tibble(br(ccn(
stats::setNames(lapply(id, fun, ...), id)
)))
}
id_name <- function(id, name) {
if (!xor(is.null(id), is.null(name))) stop("use only one of 'id' or 'name'")
if (!is.null(name)) {
unlist(lapply(name, safe_wm_name2id), FALSE)
} else {
id
}
}
safe_wm_name2id <- function(x, ...) {
res <- tryCatch(wm_name2id(x, ...), error = function(e) e)
if (inherits(res, "error")) {
warning(sprintf("%s: %s", x, res$message))
return(NULL)
} else {
return(res)
}
}
worrms/vignettes/ 0000755 0001762 0000144 00000000000 13147642433 013622 5 ustar ligges users worrms/vignettes/worrms_vignette.Rmd 0000644 0001762 0000144 00000021274 13147636503 017533 0 ustar ligges users
Introduction to the worrms package
==================================
`worrms` is an R client for the [World Register of Marine Species](http://www.marinespecies.org/).
## Install
Stable version from CRAN
```r
install.packages("worrms")
```
Development version from GitHub
```r
install.packages("devtools")
devtools::install_github("ropensci/worrms")
```
```r
library("worrms")
```
## Get records
WoRMS 'records' are taxa, not specimen occurrences or something else.
by date
```r
wm_records_date('2016-12-23T05:59:45+00:00')
#> # A tibble: 50 x 25
#> AphiaID url
#> *
#> 1 894298 http://www.marinespecies.org/aphia.php?p=taxdetails&id=894298
#> 2 894301 http://www.marinespecies.org/aphia.php?p=taxdetails&id=894301
#> 3 894297 http://www.marinespecies.org/aphia.php?p=taxdetails&id=894297
#> 4 894302 http://www.marinespecies.org/aphia.php?p=taxdetails&id=894302
#> 5 894296 http://www.marinespecies.org/aphia.php?p=taxdetails&id=894296
#> 6 894299 http://www.marinespecies.org/aphia.php?p=taxdetails&id=894299
#> 7 894303 http://www.marinespecies.org/aphia.php?p=taxdetails&id=894303
#> 8 915236 http://www.marinespecies.org/aphia.php?p=taxdetails&id=915236
#> 9 906769 http://www.marinespecies.org/aphia.php?p=taxdetails&id=906769
#> 10 909454 http://www.marinespecies.org/aphia.php?p=taxdetails&id=909454
#> # ... with 40 more rows, and 23 more variables: scientificname ,
#> # authority , status , unacceptreason , rank ,
#> # valid_AphiaID , valid_name , valid_authority ,
#> # kingdom , phylum , class , order , family ,
#> # genus , citation , lsid , isMarine ,
#> # isBrackish , isFreshwater , isTerrestrial ,
#> # isExtinct , match_type , modified
```
by a taxonomic name
```r
wm_records_name(name = 'Platanista gangetica')
#> # A tibble: 3 x 25
#> AphiaID url
#> *
#> 1 254967 http://www.marinespecies.org/aphia.php?p=taxdetails&id=254967
#> 2 383571 http://www.marinespecies.org/aphia.php?p=taxdetails&id=383571
#> 3 254969 http://www.marinespecies.org/aphia.php?p=taxdetails&id=254969
#> # ... with 23 more variables: scientificname , authority ,
#> # status , unacceptreason , rank , valid_AphiaID ,
#> # valid_name , valid_authority , kingdom , phylum ,
#> # class , order , family , genus , citation ,
#> # lsid , isMarine , isBrackish , isFreshwater ,
#> # isTerrestrial , isExtinct , match_type , modified
```
by many names
```r
wm_records_names(name = c('Platanista gangetica', 'Coryphaena'))
#> [[1]]
#> # A tibble: 1 x 25
#> AphiaID url
#> *
#> 1 254967 http://www.marinespecies.org/aphia.php?p=taxdetails&id=254967
#> # ... with 23 more variables: scientificname , authority ,
#> # status , unacceptreason , rank , valid_AphiaID ,
#> # valid_name , valid_authority , kingdom , phylum ,
#> # class , order , family , genus , citation ,
#> # lsid , isMarine