R/pch_clean_up.R

Defines functions pch_clean_up

Documented in pch_clean_up

#' @title pch_clean_up
#'
#' @description Parallel computing helper function to clean up the parallel
#'   backend.
#'
#' @param cl A cluster object of class `c("SOCKcluster", "cluster")`.
#'
#' @return The function returns nothing. Internally, it calls
#'   `parallel::stopCluster()` and `foreach::registerDoSEQ()`.
#'
#' @seealso [parallel::stopCluster()], [foreach::registerDoSEQ()]

#' @examples
#' if (require("doParallel") && require("foreach")) {
#'   cl <- pch_register_parallel(pch_check_available_cores(2))
#'   pch_clean_up(cl)
#' }
#' @export
#
pch_clean_up <- function(cl) {
  stopifnot(
    "`cluster` must be a SOCKcluster object" =
      inherits(cl, c("SOCKcluster", "cluster")))
  parallel::stopCluster(cl = cl)
  foreach::registerDoSEQ()
  invisible()
}

Try the kdry package in your browser

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

kdry documentation built on July 4, 2024, 9:07 a.m.