DeclareDesign / fabricatr

fabricatr: Imagine Your Data Before You Collect It
https://declaredesign.org/r/fabricatr
Other
91 stars 11 forks source link

should this work? #155

Closed graemeblair closed 6 years ago

graemeblair commented 6 years ago

This generates an error:

fabricate(
  primary_schools   = add_level(N = 5),
  secondary_schools = add_level(N = 6, nest = FALSE),
  students          = 
    link_levels(N = 15, by = join(primary_schools, secondary_schools))
)

But this, same but with a variable at the top level, does work:

fabricate(
  primary_schools = add_level(N = 20, ps_quality = runif(N, 1, 10)),
  secondary_schools = add_level(
    N = 15,
    nest = FALSE),
  students = link_levels(
    N = 1500,
    by = join(primary_schools, secondary_schools)
  )
)

Trying to demonstrate simple cross-classifying.

nfultz commented 6 years ago

Can you post the error message?

graemeblair commented 6 years ago

Sorry! Yes, including traceback:

Error in `[<-`(`*tmp*`, , ID_label, value = c("01", "02", "03", "04",  : 
  subscript out of bounds 
5.
FUN(N = N, ID_label = ID_label, by = by, workspace = working_environment_, 
    data_arguments = dots) at helper_functions.R#422
4.
do_internal(N, by = by, ..., FUN = cross_levels_internal, from = "link_level") at cross_levels.R#71
3.
link_levels(N = 15, by = join(primary_schools, secondary_schools), 
    working_environment_ = <environment>, ID_label = "students") 
2.
eval_tidy(dots[[i]]) at aaa_fabricate.R#184
1.
fabricate(primary_schools = add_level(N = 5), secondary_schools = add_level(N = 6, 
    nest = FALSE), students = link_levels(N = 15, by = join(primary_schools, 
    secondary_schools))) 
nfultz commented 6 years ago

See commit above and add your snippet as a regression test.