#!/usr/bin/env Rscript # # make_samples.R — Metrika # # Author: Simon-Pierre Boucher # Contact: contact@spboucher.ai # Copyright © 2026 Simon-Pierre Boucher. All rights reserved. # # Generates the sample datasets bundled with the app (loaded via the # `sysuse` command). Deterministic: fixed seed, values rounded so the # CSVs are bit-stable across regenerations. # out <- file.path( dirname(dirname(normalizePath(sub("--file=", "", grep("--file=", commandArgs(FALSE), value = TRUE))))), "MetrikaKit", "Sources", "ZQEngine", "Resources", "Samples" ) dir.create(out, recursive = TRUE, showWarnings = FALSE) # sales — the CLAUDE.md flagship example: firm-year panel of revenue and # price with regional effects. 200 firms × 5 years. set.seed(2026) firms <- 200 years <- 2019:2023 n <- firms * length(years) firm_id <- rep(seq_len(firms), each = length(years)) year <- rep(years, times = firms) region <- rep(sample(1:4, firms, replace = TRUE), each = length(years)) firm_effect <- rep(round(rnorm(firms, 0, 0.3), 6), each = length(years)) price <- round(runif(n, 5, 25) + 0.4 * (year - 2019), 4) log_revenue <- 4.2 - 0.07 * price + 0.12 * (region - 1) + 0.05 * (year - 2019) + firm_effect + round(rnorm(n, 0, 0.2), 6) sales <- data.frame( firm_id = firm_id, year = year, region = region, price = price, revenue = round(exp(log_revenue), 4), employees = pmax(1, round(exp(2 + 0.5 * firm_effect + rnorm(n, 0, 0.4)))) ) write.csv(sales, file.path(out, "sales.csv"), row.names = FALSE, quote = FALSE) # mtcars — the R classic (public dataset), with the car name as a string # column so string handling has a sample too. data(mtcars) cars <- cbind(model = rownames(mtcars), mtcars) write.csv(cars, file.path(out, "mtcars.csv"), row.names = FALSE) cat("wrote", file.path(out, "sales.csv"), "and mtcars.csv\n")