View source: R/serialization.R
| write_split_spec | R Documentation |
Write a split_spec to a JSON file and read it back. The on-disk
format captures the canonical sample-level table (sample_data) plus
all spec-level fields needed by a downstream resampling adapter
(group_var, block_vars, time_var,
ordering_required, constraint_mode,
constraint_strategy, recommended_resampling) and the spec
metadata.
write_split_spec(spec, path, pretty = TRUE)
read_split_spec(path)
spec |
A |
path |
Path to write to or read from. |
pretty |
If |
NA values in sample_data are written as JSON null and
read back as NA.
write_split_spec() invisibly returns path.
read_split_spec() returns a split_spec.
{
"$schema": "https://.../inst/schema/split_spec.schema.json",
"splitGraph_object": "split_spec",
"schema_version": "0.2.0",
"group_var": "group_id",
"block_vars": ["batch_group", "study_group"],
"time_var": "order_rank",
"ordering_required": false,
"constraint_mode": "subject",
"constraint_strategy": "subject",
"recommended_resampling": "grouped_cv",
"metadata": { ... },
"sample_data": [
{ "sample_id": "S1", "group_id": "subject:P1", ... },
...
]
}
if (requireNamespace("jsonlite", quietly = TRUE)) {
meta <- data.frame(
sample_id = c("S1", "S2"),
subject_id = c("P1", "P2")
)
g <- graph_from_metadata(meta)
constraint <- derive_split_constraints(g, mode = "subject")
spec <- as_split_spec(constraint, graph = g)
tmp <- tempfile(fileext = ".json")
write_split_spec(spec, tmp)
spec2 <- read_split_spec(tmp)
identical(spec$sample_data$group_id, spec2$sample_data$group_id)
unlink(tmp)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.