Skip to content
Prev 1508 / 2152 Next

Error in UseMethod("stopCluster") : no applicable method for 'stopCluster' ...

On 09/21/2012 12:47 AM, Marius Hofert wrote:
An even more minimal example is

   ex <- function() {
       cl <- snow::makeCluster(parallel::detectCores(), type="MPI")
       snow::stopCluster(cl)
   }
   res <- ex()

To be clear, there is no library(snow) in the script, and on.exit() is 
not relevant. The reason is that snow::stopCluster is an S3 generic, and 
on the help page ?NextMethod we have


      Namespaces can register methods for generic functions.  To support
      this, 'UseMethod' and 'NextMethod' search for methods in two
      places: first in the environment in which the generic function is
      called, and then in the registration data base for the environment
      in which the generic is defined (typically a namespace).  So
      methods for a generic function need to be available in the
      environment of the call to the generic, or they must be
      registered.  (It does not matter whether they are visible in the
      environment in which the generic is defined.)

There are no stopCluster methods defined in the calling namespace (i.e., 
your script) and since there has been no call to library(snow), there is 
no snow namespace to search and hence no method to be found.

The solution is to add

   library(snow)

to the script (or better library(parallel) and use the 'parallel' 
library throughout).

Martin