statisfactions / simpr

Tidyverse-friendly simulations and power analysis
42 stars 6 forks source link

allow `specify` with arguments having differing numbers of rows #70

Open statisfactions opened 2 years ago

statisfactions commented 2 years ago

Currently specify generates a warning and no output when arguments have differing numbers of rows:

suppressPackageStartupMessages(library(simpr))
sim = specify(pre = ~ rnorm(n1),
        post = ~ rnorm(n2)) %>% 
  define(n1 = 5,
         n2 = 10) %>% 
  generate(1)
#> Warning in create_sim_results(specs = specs, x = x[c("meta_info", "specify", :
#> Simulation produced errors. See column '.sim_error'.

sim$.sim_error
#> [1] "Error: Can't recycle `..1` (size 5) to match `..2` (size 10).\n"

Created on 2022-01-20 by the reprex package (v2.0.1)

It would be nice to support this more gracefully. Two initial thoughts:

  1. When row numbers are different, bind together into list-columns. This always works but is a little convoluted, and should probably output a warning or at least a message.
  2. In addition to the above, also offer and option to pivot (and unnest) the columns to be in a long format -- so, in the above example, the output could be pivoted so that pre and post group names are in a column , with the rows also in a column.