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.
Arguments
- schema
The synthetic recipe (a list with
columns, and optionaln_rows,seed, androw_replication) .- out_path
Path where the CSV is written.
- n_rows
Number of rows (persons, if replicating) to generate. Defaults to
schema$n_rows, then 50000.- seed
Random seed for reproducibility. Defaults to
schema$seed, then 91735246.
Examples
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
#> [1] 20
res$seed # 42 (reproducible)
#> [1] 42
# The written CSV round-trips and has the declared columns.
df <- utils::read.csv(out)
dim(df)
#> [1] 20 4
names(df)
#> [1] "year" "alert" "visits" "id"
# `n_rows` overrides the recipe's own row count.
make_synthetic_csv(recipe, tempfile(fileext = ".csv"), n_rows = 5)$rows
#> [1] 5