Nesting msemtools functions within other functions causes errors
Closed this issue · 1 comments
mnoetel commented
This could just be the way I'm writing a function but I can't figure out why it's not working.
If I run the code inside the function, using the commented lines to directly parse the variables, the analyses work great.
But, run the run_analyses_reproducible function with the same parameters and I get
"Error in eval(., data, enclos = sys.frame(sys.parent())) :
invalid 'envir' argument of type 'closure' ,
d1 <- msemtools::conigrave20
run_analyses_reproducible <- function(df, one_group){
#df <- d1
#one_group <- "Urban"
df <- dplyr::filter(df, df$Remoteness == one_group) #just test for this outcome
main_model <- metaSEM::meta3(
y = drink_yi,
v = drink_vi,
cluster = study_id,
data = df,
model.name = "3 level model"
)
if(!(summary(main_model)$Mx.status1 == 0 | summary(main_model)$Mx.status1 == 1)){ # rerun on a warning
main_model <- metaSEM::rerun(main_model)
}
#summary(main_model)
main_moderators <- msemtools::moderate(main_model,
Cohort,
State)
#summary(main_moderators)
return(main_moderators)
}
run_analyses_reproducible(d1, "Urban")