节点保持打开状态

时间:2019-05-14 11:57:27

标签: r try-catch caret

当我创建节点以并行化我的代码时,我遇到了一个问题,最后R不会停止节点,而是使它们保持打开状态。我尝试了几种方法,最后结仍然保持打开状态

trainSeqNum <- as.data.frame(matrix(data=rnorm(257*60), ncol=257))
trainAct    <- runif(60, -1, 1)
# tryCatch custum
modelTryCatch <- function(expr) {
  warn <- NULL
  err <- NULL
  value <- withCallingHandlers(
    tryCatch(expr, error = function(e) {
      err <<- e
      NULL
    }), warning = function(w) {
      warn <<- w
      invokeRestart("muffleWarning")
    })
  list(value = value, warning = warn, error = err)
}

doParallel::registerDoParallel(5)
nbCore <- foreach::getDoParWorkers()

#res <-
modelTryCatch({

  R.utils::withTimeout({

    caret::train(
      trainSeqNum,
      trainAct,
      trControl = trainControl(
        method = "cv",
        number = 5,
        savePredictions = 'final',
        allowParallel = TRUE),
      method = "ANFIS",
      tuneLength = 1,
      preProcess = NULL
    )},
    timeout = 5)
})

#if(is.null(res$value)){} else {}
foreach::registerDoSEQ()
#doParallel::stopImplicitCluster()

0 个答案:

没有答案