DeclareDesign / fabricatr

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

not recognizing multivariate variable creation #188

Open graemeblair opened 2 years ago

graemeblair commented 2 years ago
> head(fabricate(
+   N = 1000,  
+   X = matrix(rnorm(3 * N), N)))
    ID         X.1        X.2        X.3
1 0001 -0.05025699 -1.6063950 -0.3198033
2 0002  0.48970821 -0.2233403 -0.1334020
3 0003 -0.27350365  0.3312467  0.2128137
4 0004  1.13195885  0.4723298  0.6101785
5 0005 -0.86154600 -0.1891876  0.5315110
6 0006  0.50783267 -1.4657854  0.4371732
> fabricate(
+   N = 1000,  
+   X = matrix(rnorm(3 * N), N),
+   Y_Z_1 = X.1)
Error in eval_tidy(data_arguments[[i]], dm) : object 'X.1' not found
nfultz commented 2 years ago

IIRC the conversion from matrix to data frame happens at the very end. As a workaround, you could pipe to a subsequent fabricatr call, or use X internally as a matrix:

fabricate(
       N = 1000,
       X = matrix(rnorm(3 * N), N),
       Y_Z_1 = X[,1])

On Fri, Jun 10, 2022 at 8:41 AM Graeme Blair @.***> wrote:

head(fabricate(

  • N = 1000,
  • X = matrix(rnorm(3 * N), N))) ID X.1 X.2 X.3 1 0001 -0.05025699 -1.6063950 -0.3198033 2 0002 0.48970821 -0.2233403 -0.1334020 3 0003 -0.27350365 0.3312467 0.2128137 4 0004 1.13195885 0.4723298 0.6101785 5 0005 -0.86154600 -0.1891876 0.5315110 6 0006 0.50783267 -1.4657854 0.4371732 fabricate(
  • N = 1000,
  • X = matrix(rnorm(3 * N), N),
  • Y_Z_1 = X.1) Error in eval_tidy(data_arguments[[i]], dm) : object 'X.1' not found

— Reply to this email directly, view it on GitHub https://github.com/DeclareDesign/fabricatr/issues/188, or unsubscribe https://github.com/notifications/unsubscribe-auth/AADGGTVLLSZ5EHGQAUH7KBLVONOWJANCNFSM5YOCRZ5Q . You are receiving this because you are subscribed to this thread.Message ID: @.***>