simcausal
simcausal copied to clipboard
cannot find function 'melt'
I've run into the issue a few times, where when I call simobs get a cannot find function 'melt' error. When I run library(data.table), the issue goes away. I have not pinpointed if I have other libraries load that may cause the conflict, but I think changing melt to data.table::melt on line 749 of simulation.R may fix the issue. Though I see that data.table::melt has been commented out.
Hi Bradley,
Thanks for filing this, but I can't replicate your issue. Is it possible that you don't have the latest version of data.table installed? Another possibility is that you may have reshape2 loaded in your environment, but I wouldn't expect that to cause an issue. data.table::melt had to be replaced with melt() to pass CRAN checks since data.table now exports its own S3 generic for melt, which might clash with the S3 generic for melt that is also exported by reshape2...
library("simcausal"); options(simcausal.verbose=FALSE)
t_end <- 5
D <- DAG.empty() +
node("W", distr="rbern", prob=0.05) +
node("L1", t=0:t_end, distr="rbern", prob=0.25) +
node("L2", t=0:t_end, distr="rconst", const=L1[t] + W) +
node("Y", t=0:t_end, distr="rbern", prob=plogis(-6.5 + L1[t] + 2*L2[t] + 0.05*sum(I(L2[0:t]==rep(0,(t+1))))), EFU=TRUE)
Dset <- set.DAG(D)
Odat1 <- sim(Dset, n=500, wide = TRUE, rndseed = 123)
Odat1 <- simobs(Dset, n=500, wide = TRUE, rndseed = 123)
Odat1 <- sim(Dset, n=500, wide = FALSE, rndseed = 123)
Odat1 <- simobs(Dset, n=500, wide = FALSE, rndseed = 123)
It may be a reshape2 issue, though I haven't add that package loaded when I've had the issue. I'll try to come up with a reproducible example, but it's not high priority.
Thanks!