Skip to content

Instantly share code, notes, and snippets.

@joelnitta
Last active May 27, 2022 21:42
Show Gist options
  • Save joelnitta/057feb5a13a8ad3fce77cc7204e20db9 to your computer and use it in GitHub Desktop.
Save joelnitta/057feb5a13a8ad3fce77cc7204e20db9 to your computer and use it in GitHub Desktop.
Example of using contentid
library(tidyverse)
#' Parse fossil calibration data in Sundue and Testo 2016 SI
#'
#' Testo WL, Sundue MA (2016) A 4000-species dataset provides new insight into
#' the evolution of ferns. Molecular Phylogenetics and Evolution 105:200–211.
#' https://doi.org/10.1016/j.ympev.2016.09.003
#'
#' @param testo_sundue_2016_si_path Path to Sundue and Testo 2016 SI file
#' (xlsx format).
#'
#' @return Tibble with fossil calibration dates
#'
parse_ts_calibrations <- function(testo_sundue_2016_si_path) {
readxl::read_excel(
testo_sundue_2016_si_path,
# Divergence dates are in the 3rd sheet
sheet = 3
) %>%
janitor::clean_names() %>%
mutate(
stem_crown = str_to_lower(stem_crown),
clade =
str_replace_all(clade, "Aglaomorpha heraclea", "Drynaria heraclea") %>%
str_replace_all("Alsophila/Cyathea clade", "Alsophila+Cyathea") %>%
str_replace_all("Isoetales", "Isoëtales") %>%
str_replace_all(" ", "_")) %>%
transmute(
minimum_age = age,
node_calibrated = paste(stem_crown, clade),
fossil_taxon = fossil,
affinities_group = stem_crown,
affinities = clade
) %>%
mutate(across(
c(node_calibrated, affinities),
~str_replace_all(., "Polypodium", "Polypodium s.l.")))
}
ts_fossil_calibration_points <- parse_ts_calibrations(
testo_sundue_2016_si_path = contentid::resolve(
# hash corresponds to the URL of the file on github
"hash://sha256/c629f4617e7e2329a10cb1b207b82a6720653a67eafcaaa97cc6ee891ae7fdf7"
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment