FunWithR / MonteCarlo

An R package for simulation studies.
33 stars 15 forks source link

Bug in simple example? #2

Closed MarkusBonsch closed 6 years ago

MarkusBonsch commented 7 years ago

Maybe I'm too stupid, but shouldn't this work?

library(MonteCarlo)

myFun <- function(a,b){
   return(list(res = a+b))
}
MonteCarlo(func = myFun, nrep = 100, param_list = list(a = 1, b = 1))

It fails in my case (R3.3.2, see complete sessionInfo below) with the following error:

Error in MonteCarlo(func = myFun, nrep = 100, param_list = list(a = 1,  : 
  object 'packages' not found

Kind regards, Markus

sessionInfo()

R version 3.3.2 (2016-10-31)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

locale:
[1] LC_COLLATE=German_Germany.1252  LC_CTYPE=German_Germany.1252    LC_MONETARY=German_Germany.1252
[4] LC_NUMERIC=C                    LC_TIME=German_Germany.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] MonteCarlo_1.0.2     snowfall_1.84-6.1    snow_0.4-2           rlecuyer_0.3-4       codetools_0.2-15    
 [6] abind_1.4-5          RevoUtilsMath_10.0.0 RevoUtils_10.0.2     RevoMods_10.0.0      MicrosoftML_1.0.0   
[11] mrsdeploy_1.0        RevoScaleR_9.0.1     lattice_0.20-34      rpart_4.1-10        

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.10           CompatibilityAPI_1.1.0 digest_0.6.12          foreach_1.4.3          grid_3.3.2            
 [6] R6_2.2.0               jsonlite_1.1           magrittr_1.5           stringi_1.1.3          pryr_0.1.2            
[11] curl_2.2               cachifyR_0.1           iterators_1.0.8        tools_3.3.2            stringr_1.2.0         
[16] mrupdate_1.0.0
FunWithR commented 7 years ago

Hi! You are perfectly right. That should work. I thought that was fixed already. Thanks for letting me know. It will be fixed with the next Update. The problem is that no function is used inside of MyFun(). MonteCarlo() runs some internal analytics to find out which functions to export to the cluster in case of parallelized execution. Those assume that there is some function used inside - such as a random number generator that you would typically need for a simulation study. But of course the toy example should work! Sorry for that!