View source: R/io_immundata_write.R
| write_immundata | R Documentation |
Save ImmunData to disk so you can close R and continue the work later (I cannot
believe it, but it works, I tried it). Use
write_immundata() after importing or transforming repertoire data, or when
you want a named snapshot before the next analysis step.
The unit saved is the complete ImmunData object. This includes retained chain rows, cell and receptor identifiers, repertoire and stratum definitions, and provenance. Saving does not add, remove, or change any biological unit.
write_immundata(
idata,
output_folder = NULL,
tag = NULL,
rehome = FALSE,
compression = "zstd",
compression_level = 9,
verbose = getOption("immundata.verbose", TRUE)
)
idata |
An ImmunData object you want to save. |
output_folder |
A character string or |
tag |
A character string or |
rehome |
A logical value. Whether an explicit |
compression |
A character string or |
compression_level |
A number or |
verbose |
A logical value. Whether to print progress and summary
messages. Defaults to |
Save to an explicit folder for a direct saved state, or use the object's home to create a versioned managed snapshot.
Invisibly returns a newly reopened, disk-backed ImmunData object
with provenance for the new save. The input idata remains unchanged.
Supply output_folder to save a standalone state in a specific directory.
This is useful when sharing a dataset or choosing its first project home.
If the directory already contains an ImmunData dataset, its
annotations.parquet and metadata.json are replaced.
Leave output_folder = NULL to create a managed snapshot. The function uses
the object's home path and writes the next version under
snapshots/<tag>/vNNN, for example snapshots/baseline/v001. Later writes
with the same tag create v002, v003, and so on; earlier versions remain
available. Use read_immundata() with tag and version to reopen one.
Every save receives a new snapshot identifier and appends a provenance event. The returned object records the new saved directory as its current path.
The retained chain-level annotation table is materialized as compressed
annotations.parquet. Materialization executes any pending lazy duckplyr
calculations. metadata.json serializes format and package versions,
receptor, repertoire, and stratum schemas, the small repertoire table, the
snapshot identifier, lineage events, and provenance paths.
Receptor and stratum views are not written as separate files; they can be reconstructed from the annotation table and metadata. This Parquet and JSON pair is an ImmunData-specific serialization, not an RDS file.
read_immundata() for continuing a saved analysis,
read_repertoires() for importing AIRR-seq files, ImmunData
library(immundata)
library(dplyr)
options(immundata.verbose = FALSE)
# Save a small immune-repertoire analysis
idata <- get_test_idata()
save_dir <- tempfile("saved-immundata-")
saved_idata <- write_immundata(idata, save_dir)
list.files(save_dir)
# Expected result: the analysis is serialized as two files.
# [1] "annotations.parquet" "metadata.json"
# Continue the analysis from the saved files
continued_idata <- read_immundata(save_dir)
continued_idata |>
collect() |>
summarise(
n_chains = n(),
n_receptors = n_distinct(imd_receptor_id)
)
# Expected result: all 1,902 chain rows and 1,668 receptors are restored.
# n_chains n_receptors
# 1902 1668
unlink(save_dir, recursive = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.