View source: R/lib_synthetic.R
| make_synthetic_csv | R Documentation |
Generates a reproducible synthetic data set from the
schema$synthetic_recipe block of a provenance object and writes it to
a CSV. Columns are produced in declaration order so later columns can
reference earlier ones, a shared per-row latent propensity drives any
Bernoulli columns, and an optional row-replication block expands
per-person rows.
make_synthetic_csv(schema, out_path, n_rows = NULL, seed = NULL)
schema |
The synthetic recipe (a list with |
out_path |
Path where the CSV is written. |
n_rows |
Number of rows (persons, if replicating) to generate.
Defaults to |
seed |
Random seed for reproducibility. Defaults to |
Invisibly, a list with path, rows (rows written), and
seed used.
recipe <- list(
n_rows = 20, seed = 42,
columns = list(
year = list(type = "sample", values = list(2024, 2025)),
alert = list(type = "bernoulli", p = 0.2),
visits = list(type = "poisson", lambda = 3, min = 1),
id = list(type = "id_pattern", pattern = "p-{seq:05d}")
)
)
out <- tempfile(fileext = ".csv")
res <- make_synthetic_csv(recipe, out)
res$rows # 20
res$seed # 42 (reproducible)
# The written CSV round-trips and has the declared columns.
df <- utils::read.csv(out)
dim(df)
names(df)
# `n_rows` overrides the recipe's own row count.
make_synthetic_csv(recipe, tempfile(fileext = ".csv"), n_rows = 5)$rows
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.