statisfactions / simpr

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

Metaparameters are blocked by global environment #3

Closed statisfactions closed 4 years ago

statisfactions commented 4 years ago

The current implementation of metaparameters fails when there is an object in the global environment that is the same as the metaparameter.

n = "barf"

variables(x1 = ~ 2 + rnorm(n)) %>% 
  meta(n = 10) %>% 
  gen(1)

Yields the following errors & warnings:

The following object is masked _by_ .GlobalEnv:

    n

The following objects are masked from meta_cell (pos = 3):

    n, rep

Error in rnorm(n) : invalid arguments
In addition: Warning message:

There is a variable scoping mess here and there likely needs to be a serious rewriting of the metaparameter implementation.

statisfactions commented 4 years ago

Expected behavior is that the global environment variable, n, is ignored by gen().

statisfactions commented 4 years ago

@jkbye could you write a unit test for this?

statisfactions commented 4 years ago

@jkbye -- never mind, I'm working on this now and am writing several unit tests including the one I requested.