[R] Ignoring loadNamespace errors when loading a file

Allan Engelhardt allane at cybaea.com
Mon Aug 22 17:56:52 CEST 2011



On 22/08/11 12:26, Martin Morgan wrote:
> On 08/21/2011 11:52 PM, Allan Engelhardt wrote:
>> [...]
>> Obligatory reproducible example: On the Unix machine do
>>
>> library("multicore")
>> a <- list(data = 1:10, fun = mclapply)
>> save(a, file = "a.RData")
>>
>> and then try to load the "a.RData" file on Windows. The question is if I
>> can recover the data (1:10) on that platform.
>
> Is this a more realistic reproducible example (from ?rfe, modified to 
> use computeFunction=mclapply)?
>
>   data(BloodBrain)
>
>   x <- scale(bbbDescr[,-nearZeroVar(bbbDescr)])
>   x <- x[, -findCorrelation(cor(x), .8)]
>   x <- as.data.frame(x)
>
>   set.seed(1)
>   lmProfile <- rfe(x, logBBB,
>                    sizes = c(2:25, 30, 35, 40, 45, 50, 55, 60, 65),
>                    rfeControl = rfeControl(functions = lmFuncs,
>                      number = 5,
>                      computeFunction=mclapply))
>
> Maybe provide a computeFunction that only indirectly references mclapply
>
>   computeFunction=function(...) {
>       if (require(multicore)) mclapply(...)
>       else lapply(...)
>   }
>
> [...]

Yes, that workaround works for my usage.  Thanks!

Allan



More information about the R-help mailing list