Skip to contents

Apply a reconciliation and save three files: the aligned CSV, the pruned tree, and the full mapping tibble. Intended for producing analysis-ready, archivable outputs — drop the three files into a Zenodo deposit or a project's data-output/ folder alongside the reconciliation report and you have a fully documented provenance trail.

Usage

reconcile_export(
  reconciliation,
  data = NULL,
  tree = NULL,
  species_col = NULL,
  dir = ".",
  prefix = "reconciled",
  tree_format = c("nexus", "newick"),
  drop_unresolved = TRUE
)

Arguments

reconciliation

A reconciliation object returned by reconcile_tree(), reconcile_data(), or a related matcher.

data

A data frame to align. If NULL, only the tree and mapping are written.

tree

An ape::phylo object or file path. If NULL, only the data and mapping are written.

species_col

A length-1 character vector. Column name in data containing species names. Auto-detected when NULL.

dir

A length-1 character vector. Path to the output directory that will receive the exported files (e.g. a project's data-output/ folder, or a staging directory before a Zenodo deposit). Created if it does not exist. Default ".".

prefix

A length-1 character vector. File name prefix. Default "reconciled".

tree_format

A length-1 character vector. Tree output format: "nexus" (default) or "newick".

drop_unresolved

Logical. Drops unresolved species when TRUE. Default TRUE.

Value

A named list of file paths (invisibly): $data (CSV), $tree (Nexus or Newick), $mapping (CSV), and $unused_overrides (CSV; NULL when there are no rejected overrides on the reconciliation).

Examples

data(avonet_subset)
data(tree_jetz)
result <- reconcile_tree(avonet_subset, tree_jetz,
                         x_species = "Species1", authority = NULL)
#>  Reconciling 919 data names vs 657 tree tips
#>  Matching 919 x 657 names through 2 stages...
#>  Stage 1/2: Exact matching...
#>  Stage 2/2: Normalised matching (0 matched so far)...
#>  Matched 657/919 data names to tree tips
out_dir <- tempfile("export_")
files <- reconcile_export(result,
                          data = avonet_subset, tree = tree_jetz,
                          species_col = "Species1",
                          dir = out_dir, prefix = "avonet_jetz")
#> ! Dropped 262 rows with unresolved species from data
#>  Tree has 657 tips after alignment
#>  Data written to /var/folders/7x/ytfpq14s0v18frbm9v_w9f4c0000gq/T//Rtmphv6sDQ/export_2dc62f7f5a71/avonet_jetz_data.csv
#>  Tree written to /var/folders/7x/ytfpq14s0v18frbm9v_w9f4c0000gq/T//Rtmphv6sDQ/export_2dc62f7f5a71/avonet_jetz_tree.nex
#>  Mapping written to /var/folders/7x/ytfpq14s0v18frbm9v_w9f4c0000gq/T//Rtmphv6sDQ/export_2dc62f7f5a71/avonet_jetz_mapping.csv
files$data     # path to CSV
#> [1] "/var/folders/7x/ytfpq14s0v18frbm9v_w9f4c0000gq/T//Rtmphv6sDQ/export_2dc62f7f5a71/avonet_jetz_data.csv"
files$tree     # path to Nexus tree
#> [1] "/var/folders/7x/ytfpq14s0v18frbm9v_w9f4c0000gq/T//Rtmphv6sDQ/export_2dc62f7f5a71/avonet_jetz_tree.nex"
files$mapping  # path to mapping CSV
#> [1] "/var/folders/7x/ytfpq14s0v18frbm9v_w9f4c0000gq/T//Rtmphv6sDQ/export_2dc62f7f5a71/avonet_jetz_mapping.csv"
unlink(out_dir, recursive = TRUE)  # clean up