Parsing error in MonteCarlo::MonteCarlo function in R

I am trying to run a power analysis using a MonteCarlo approach in R.

I have created a function of two parameters that does output a boolean (tested manually for all relevant values of the parameters). I also have run baby-examples of the MonteCarlo function to make sure that I understand it and that it works well.

Yet when I try to run the real thing, I get the following error message:

 Error in parse(text = all_funcs_found[i]) : <text>:1:1: unexpected '::' 
 1: ::

I read through the source code of the MonteCarlo function (which I found here) and found

 #loop through non-primitive functions used in func and check from which package they are

 for(i in 1:length(all_funcs_found)){
   if(environmentName(environment(eval(parse(text=all_funcs_found[i]))))%in%env_names){
     packages<-c(packages,env_names[which(env_names==environmentName(environment(eval(parse(text=all_funcs_found[i])))))])
   }
 }

which doesn't really make sense to me - why should there be a problem there?

Thank you for any ideas.

1 answer

  • answered 2021-05-03 18:10 Arnaud Mortier

    I found the answer: the function I wrote was calling a function from a specific library in the form libraryname::functionname.

    This works OK if you use the function once manually, but makes MonteCarlo break.

    I solved the problem by first loading the relevant library, then removing the 'libraryname::' part from the definition of the main function. MonteCarlo then runs just fine.