Skip to content

Commit

Permalink
Merge pull request ropensci#329 from laijasmine/master
Browse files Browse the repository at this point in the history
align `set_taxonomicCoverage` behaviour with EML
  • Loading branch information
cboettig committed Jun 7, 2021
2 parents 54052b9 + 4f78b4b commit 6f5806f
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 21 deletions.
27 changes: 13 additions & 14 deletions R/set_coverage.R
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ set_temporalCoverage <-
#' @export
#' @importFrom methods is
#' @examples
#'
#' taxon_coverage <- set_taxonomicCoverage("Macrocystis pyrifera")
#'
#' sci_names <- data.frame(
#' Kingdom = "Plantae",
Expand All @@ -148,21 +150,21 @@ set_temporalCoverage <-
#' Order = "Laminariales",
#' Family = "Lessoniaceae",
#' Genus = "Macrocystis",
#' Species = "pyrifera"
#' specificEpithet = "pyrifera"
#' )
#' taxon_coverage <- set_taxonomicCoverage(sci_names)
#'
#' \donttest{ # Examples that may take > 5s
#'
#' ## use a list of lists for multiple species
#' sci_names <- list(list(
#' Kindom = "Plantae",
#' Kingdom = "Plantae",
#' Phylum = "Phaeophyta",
#' Class = "Phaeophyceae",
#' Order = "Laminariales",
#' Family = "Lessoniaceae",
#' Genus = "Macrocystis",
#' Species = "pyrifera"
#' specificEpithet = "pyrifera"
#' ))
#' set_taxonomicCoverage(sci_names)
#'
Expand All @@ -173,16 +175,10 @@ set_taxonomicCoverage <- function(sci_names, expand = FALSE, db = "itis") {
sci_names <- expand_scinames(sci_names, db)
}
if (is.character(sci_names) && !expand) {
taxa <- lapply(strsplit(sci_names, " "), function(s) {
list(
taxonRankName = "Genus",
taxonRankValue = s[[1]],
taxonomicClassification = list(
taxonRankName = "Species",
taxonRankValue = s[[2]]
)
taxa <- list(
taxonRankName = "Species",
taxonRankValue = sci_names
)
})
list(taxonomicClassification = taxa)
} else if (is.data.frame(sci_names)) {
set_taxonomicCoverage.data.frame(sci_names)
Expand All @@ -194,7 +190,7 @@ set_taxonomicCoverage <- function(sci_names, expand = FALSE, db = "itis") {
can only be character string, data.frame or list")
}
}



## Recursively turn named list into nested list
Expand Down Expand Up @@ -240,5 +236,8 @@ expand_scinames <- function(sci_names, db){
"Expansion of scientific names requires the 'taxadb' package to be installed. Install taxadb or set expand to FALSE."
)}
df <- taxadb::filter_name(sci_names, provider = db)
as.list(df[c("kingdom", "phylum", "class", "order", "family", "genus", "specificEpithet")])

lapply(1:length(sci_names), function(i){
as.list(df[i,c("kingdom", "phylum", "class", "order", "family", "genus", "specificEpithet")])})

}
8 changes: 5 additions & 3 deletions man/set_taxonomicCoverage.Rd

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

6 changes: 3 additions & 3 deletions tests/testthat/test-set_taxonomicCoverage.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ test_that("set_taxonomicCoverage works with data.frame", {
Order = "Laminariales",
Family = "Lessoniaceae",
Genus = "Macrocystis",
Species = "pyrifera"
specificEpithet = "pyrifera"
)
taxon_coverage <- set_taxonomicCoverage(sci_names)

Expand All @@ -20,13 +20,13 @@ test_that("set_taxonomicCoverage works with data.frame", {

test_that("set_taxonomicCoverage works with nested lists", {
sci_names <- list(list(
Kindom = "Plantae",
Kingdom = "Plantae",
Phylum = "Phaeophyta",
Class = "Phaeophyceae",
Order = "Laminariales",
Family = "Lessoniaceae",
Genus = "Macrocystis",
Species = "pyrifera"
specificEpithet = "pyrifera"
))
x <- set_taxonomicCoverage(sci_names)

Expand Down
2 changes: 1 addition & 1 deletion vignettes/working-with-units.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ author: "Carl Boettiger"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{Working with units}
%\VignetteIndexEntry{Working with Units}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
Expand Down

0 comments on commit 6f5806f

Please sign in to comment.