Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When executing in parallel, vertexEffectSize() fails when the formula in the prior vertexLm() call is stored in a variable. #305

Open
dnmacdon opened this issue Feb 12, 2022 · 0 comments

Comments

@dnmacdon
Copy link

dnmacdon commented Feb 12, 2022

This works:

library(RMINC)

#df, formulaString defined

form <- as.formula(formulaString)
sa_model <- vertexLm(form, data=df)
sa_es <- vertexEffectSize(sa_model)

This fails:

library(RMINC)
library(parallel)

#df, formulaMatrix defined
#df is data frame
#formulaMatrix contains formula strings to loop over

cl <- makeForkCluster(nNodes)

parApply( cl, formulaMatrix, 1, function(formulaString)
{
  form <- as.formula(formulaString)
  sa_model <- vertexLm(form, data=df)
  sa_es <- vertexEffectSize(sa_model)
} )
Error in checkForRemoteErrors(val) : 
  18 nodes produced errors; first error: object 'form' not found

The error occurs in line 87 of RMINC's effectsize.R. The modification shown below seems to alleviate the problem, at least in this particular use case. However, I'm not certain why these behave differently because, if I understand the R docs correctly, these two calls should be equivalent since eval defaults to the parent environment anyways.

# effectsize.R line 87. This fails when vertexEffectSize() is executed in parallel by parLapply().
mod_mat <- eval(model_call)
# Mod to force evaluation in parent environment
mod_mat <- eval.parent(model_call,n=1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant