## ----include = FALSE----------------------------------------------------------
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  # Every chunk below queries a remote service (Open Tree of Life, NCBI,
  # Fish Tree of Life). To keep the vignette buildable offline and on CRAN,
  # code is shown but not evaluated. Run it yourself in an interactive
  # session with network access.
  eval = FALSE
)

## ----setup--------------------------------------------------------------------
# library(aptg)

## ----mixed--------------------------------------------------------------------
# res <- taxa.tree(c(
#   "Canis lupus", "Alces alces", "Rangifer tarandus",   # phylum Chordata
#   "Acer saccharum", "Acer rubrum", "Betula alleghaniensis"  # phylum Streptophyta
# ))
# 
# names(res$trees)
# #> [1] "Chordata"     "Streptophyta"

## ----inspect------------------------------------------------------------------
# chordata <- res$trees[["Chordata"]]
# 
# chordata$tree            # an ape "phylo" object
# chordata$dist            # pairwise distances among the three mammals
# 
# # Plot just the plant tree:
# plot(res$trees[["Streptophyta"]]$tree)

## ----unmatched----------------------------------------------------------------
# res$unmatched

## ----downto-------------------------------------------------------------------
# # Every species in the deer family:
# deer <- downto.tree("Cervidae", downto = "species")
# names(deer$trees)
# #> [1] "Chordata"

## ----fish-install-------------------------------------------------------------
# install.packages("fishtree")  # once

## ----fish---------------------------------------------------------------------
# fish <- taxa.tree(
#   c("Thunnus thynnus", "Gadus morhua", "Danio rerio", "Salmo salar"),
#   source = "fish"
# )
# 
# tr <- fish$trees[["Actinopterygii"]]$tree
# plot(tr)
# 
# # These branch lengths are real, so cophenetic() gives patristic (time)
# # distances rather than edge counts:
# fish$trees[["Actinopterygii"]]$dist

## ----region-------------------------------------------------------------------
# # Birds within 50 km of Montreal:
# region.tree("Aves", lat = 45.50, lon = -73.57, radius_km = 50)
# 
# # Mammals of a Canadian territory (all 13 provinces/territories work,
# # by name or postal code):
# region.tree("Mammalia", province = "Nunavut")
# 
# # Freshwater fishes of Quebec as a dated tree:
# region.tree("Actinopterygii", province = "QC", source = "fish")
# 
# # Anywhere in the world via a GADM GID:
# region.tree("Reptilia", gadm = "USA.5_1")

