Write an aligned dataset, tree, and mapping table to disk
Source:R/reconcile_export.R
reconcile_export.RdApply 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::phyloobject or file path. IfNULL, only the data and mapping are written.- species_col
A length-1 character vector. Column name in
datacontaining species names. Auto-detected whenNULL.- 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. DefaultTRUE.
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).
See also
reconcile_apply() for in-memory alignment without writing
to disk; reconcile_report() for a self-contained HTML audit
trail.
Other reconciliation functions:
reconcile_apply(),
reconcile_augment(),
reconcile_crosswalk(),
reconcile_data(),
reconcile_diff(),
reconcile_mapping(),
reconcile_merge(),
reconcile_multi(),
reconcile_override(),
reconcile_override_batch(),
reconcile_plot(),
reconcile_report(),
reconcile_review(),
reconcile_splits_lumps(),
reconcile_suggest(),
reconcile_summary(),
reconcile_to_trees(),
reconcile_tree(),
reconcile_trees()
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