library("knitr")
hook_output <- knitr::knit_hooks$get("output")
knitr::knit_hooks$set(output = function(x, options) {
   lines <- options$output.lines
   if (is.null(lines)) {
     return(hook_output(x, options))  # pass to default hook
   }
   x <- unlist(strsplit(x, "\n"))
   more <- "..."
   if (length(lines)==1) {        # first n lines
     if (length(x) > lines) {
       # truncate the output, but add ....
       x <- c(head(x, lines), more)
     }
   } else {
     x <- c(if (abs(lines[1])>1) more else NULL,
            x[lines],
            if (length(x)>lines[abs(length(lines))]) more else NULL
           )
   }
   # paste these lines together
   x <- paste(c(x, ""), collapse = "\n")
   hook_output(x, options)
 })

knitr::opts_chunk$set(
  comment = "#>",
  collapse = TRUE,
  warning = FALSE,
  message = FALSE
)

binomen introduction

binomen provides various taxonomic classes for defining a single taxon, multiple taxa, and a taxonomic data.frame

It is sort of a companion to taxize, where you can get taxonomic data on taxonomic names from the web.

The classes (S3):

The verbs:

Install

Stable version from CRAN

install.packages("binomen")

Development version from GitHub

install.packages("devtools")
devtools::install_github("ropensci/binomen")
library("binomen")

Make a taxon

Make a taxon object

(obj <- make_taxon(genus="Poa", epithet="annua", authority="L.",
  family='Poaceae', clazz='Poales', kingdom='Plantae', variety='annua'))

Index to various parts of the object

The binomial

obj$binomial

The authority

obj$binomial$authority

The classification

obj$grouping

The family

obj$grouping$family

Subset taxon objects

Get one or more ranks via pick()

obj %>% pick(family)
obj %>% pick(family, genus)

Drop one or more ranks via pop()

obj %>% pop(family)
obj %>% pop(family, genus)

Get a range of ranks via span()

obj %>% span(kingdom, family)

Extract classification as a data.frame

gethier(obj)

Taxonomic data.frame's

Make one

df <- data.frame(order = c('Asterales','Asterales','Fagales','Poales','Poales','Poales'),
  family = c('Asteraceae','Asteraceae','Fagaceae','Poaceae','Poaceae','Poaceae'),
  genus = c('Helianthus','Helianthus','Quercus','Poa','Festuca','Holodiscus'),
  stringsAsFactors = FALSE)
(df2 <- taxon_df(df))

Parse - get rank order via pick()

df2 %>% pick(order)

get ranks order, family, and genus via pick()

df2 %>% pick(order, family, genus)

get range of names via span(), from rank X to rank Y

df2 %>% span(family, genus)

Separate each row into a taxon class (many taxon objects are a taxa class)

scatter(df2)

And you can re-assemble a data.frame from the output of scatter() with assemble()

out <- scatter(df2)
assemble(out)


ropensci/binomen documentation built on May 18, 2022, 9:47 a.m.