Skip to content

Ignoring loadNamespace errors when loading a file

4 messages · Allan Engelhardt, Uwe Ligges, Martin Morgan

#
On a Unix machine I ran caret::rfe using the multicore package, and I 
saved the resulting object using save(lm2, file = "lm2.RData").  
[Reproducible example below.]

When I try to load("lm2.RData") on my Windows laptop, I get

Error in loadNamespace(name) : there is no package called 'multicore'

I completely understand the error and I would like to ignore it and 
still load the saved object data.

I imagine that I can make myself an empty multicore package for Windows 
and load the data file successfully, but is there another way?

(I am not going to use any multicore functionality; I just want to 
inspect some of the data stored in the object and the reference in 
question is just an unfortunately stored link from the original call.)

(I did search for this question in the archives, but could only find it 
discussed in connection with starting R with a .RData file where the 
consensus seems to be to start R in vanilla mode and install the missing 
package.  This situation is different and installing a Unix-only package 
on Windows is obviously a non-starter, except as I proposed above.)

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.

Allan
R version 2.13.1 (2011-07-08)
Platform: x86_64-pc-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=English_United Kingdom.1252
[2] LC_CTYPE=English_United Kingdom.1252
[3] LC_MONETARY=English_United Kingdom.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United Kingdom.1252

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

other attached packages:
[1] caret_4.98      cluster_1.14.0  reshape_0.8.4   plyr_1.6
[5] lattice_0.19-31 boot_1.3-2      ctv_0.7-3

loaded via a namespace (and not attached):
[1] grid_2.13.1  tools_2.13.1
#
On 22.08.2011 08:52, Allan Engelhardt wrote:
Short answer: No.

The element "fun" within "a" relies on the Namespace being present. And 
then you want additionally just part of an object. If this is really 
relevant, you have to digg into ./src/main/saveload.R and serialize.R 
and try to write your own interface to extract parts of objects. So this 
is probably not worth the effort.

Uwe Ligges
#
On 08/21/2011 11:52 PM, Allan Engelhardt wrote:
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(...)
   }

or editing the result object to remove references to mclapply

   lmProfile$control$computeFunction <- NULL

Martin

  
    
#
On 22/08/11 12:26, Martin Morgan wrote:
Yes, that workaround works for my usage.  Thanks!

Allan