I like the “multicore” library for a particular task. I can easily write a combination of
if(require("multicore",...)) that means that my function will automatically use the parallel
mclapply() instead of
lapply() where it is available. Which is grand 99% of the time, except when my function is called from
mclapply() (or one of the lower level functions) in which case much CPU trashing and grinding of teeth will result.
So, I needed a function to determine if my function was called from any function in the “multicore” library. Here it is.
First define a generally useful function:
Then we use it for our purpose:
Easy when you know how.