Serialises exactly the files a site is expected to return, and nothing else. Every filename is prefixed with the sample identifier, so bundles from different sites remain distinguishable when they are loose files in one directory rather than in separate folders.
Usage
write_transport(
x,
dir,
sample_info = NULL,
flow = NULL,
caps_agreement = NULL,
session_info = FALSE
)Arguments
- x
A
ptsdiag_transportobject.- dir
Directory to write into. Required, and must already exist: the function never creates directories and never guesses a location, so a mistyped path fails rather than scattering files.
- sample_info, flow
Named lists of aggregate descriptives, or
NULL.- caps_agreement
A data frame of counts against a clinician interview, or
NULL.- session_info
Whether to write
sessionInfo()alongside.FALSEby default, so nothing about the local machine leaves it unless you ask.
Details
sample_info and flow must be plain lists of aggregates. They
are written as JSON deliberately: a gtsummary or ggplot2 object
would carry a reference to the source data inside it.
Examples
# \donttest{
ptsd_data <- rename_ptsd_columns(
simulated_ptsd_genpop[1:400, c("patient_id", paste0("S", 1:20))],
id_col = "patient_id")
fit <- score_all_combinations(ptsd_data, n_symptoms = 3, n_required = 2,
show_progress = FALSE)
plateau <- compute_plateau(fit, delta = 1)
bundle <- transport_plateau(
ptsd_data,
plateau_specs = list(list(derivation = "example", rule_form = "flat_2_3",
delta = 1, n_required = 2, clusters = NULL,
sets = plateau$sets$combination_id)),
named_specs = list(list(derivation = "example", rule_form = "flat_2_3",
n_required = 2, clusters = NULL,
sets = fit$combination_id[1:3], ranks = 1:3)),
sample_id = "site_a"
)
# Write into a temporary directory, then clean up
out <- file.path(tempdir(), "transport_example")
dir.create(out, showWarnings = FALSE)
write_transport(bundle, out)
#> ✔ Wrote 2 files for "site_a" to /tmp/Rtmp2dnlav/transport_example.
#> ℹ Return all of them, and nothing else.
list.files(out)
#> [1] "site_a_named_sets.csv" "site_a_transport_summary.csv"
unlink(out, recursive = TRUE)
# }
