R/rtopCluster.R

Defines functions rtopCluster

Documented in rtopCluster

rtopCluster = function(nclus, ..., action = "start", type, outfile = NULL ) {
  cl = getOption("rtopCluster")
  if (length(cl) > 0 && (action == "stop" | action == "restart")) {
    parallel::stopCluster(cl)
    options(rtopCluster = NULL)
  } 
  if (length(cl) > 0 && action == "start") {
    if (length(list(...)) > 0) parallel::clusterEvalQ(cl, ...)
  } else if (action == "start" | action == "restart") {
    if (!requireNamespace("parallel")) stop("Not able to start cluster, parallel not available")
    if (missing(type) || is.null(type)) {
      cl <- parallel::makeCluster(nclus, outfile = outfile) 
    } else {
      cl <- parallel::makeCluster(nclus, type, outfile = outfile)
    }
#    doParallel::registerDoParallel(cl, nclus)
    if (length(list(...)) > 0) parallel::clusterEvalQ(cl, ...)
    options(rtopCluster = cl)    
  }
  getOption("rtopCluster")
}

Try the rtop package in your browser

Any scripts or data that you put into this service are public.

rtop documentation built on May 2, 2019, 6:48 p.m.