Cannot run stan model in parallel under Rstudio (within a R package)

Hi!

I am hoping that this rings some bells here as I am out of ideas how to debug this problem: I am writing a R package which I have started by using the rstantools wrapper. The model has the name “blrm_exnex” and parallelization with cores=2 works fine under the terminal. However, under Rstudio I am running into trouble when cores>1. The error message I am getting is

Warning: namespace ‘anRpackage’ is not available and has been replaced
by .GlobalEnv when processing object ‘’
 Error in checkForRemoteErrors(val) : 
  2 nodes produced errors; first error: object 'model_blrm_exnex' not found

This is somehow related to the use of parLapplyLB (and the cluster stuff). However, I really do not get whats up here. The thing is that rstanarm 2.17.3 works just fine in parallel and there I do not see what is supposed to be different.

I know this is a terrible request to ask for help here, but maybe this rings a bell to someone as to what could go wrong here. So the sampling call for the blrm_exnex model inside a function of my package does not work.

What is really confusing me is that I have another package where parallelization works under Rstudio, but I cannot find any striking difference here. Maybe there is something obvious I am overlooking.

Thanks for any pointers.

Best,
Sebastian

Never mind. Problem is caused by a very subtle configuration thing of our R installation. Now it works. The solution is to ensure that the package you are using is in the .libPaths() of R. So loading a package via

library(myPackage, lib.loc=whatever)

and whatever is not part of .libPaths() defeats the parallelization.

Sorry for the noise.