From e5f2da86712870daac66d45cdff60247efcec22c Mon Sep 17 00:00:00 2001 From: s-kganz Date: Wed, 23 Jun 2021 18:27:46 -0700 Subject: [PATCH] add disclaimer for ncores on Windows in tests, prevent SCUT_parallel example from triggering a warning --- R/scut.R | 7 ++++--- man/SCUT.Rd | 6 ++++-- tests/testthat/test-scut.R | 7 ++----- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/R/scut.R b/R/scut.R index ad9a676..559db6d 100644 --- a/R/scut.R +++ b/R/scut.R @@ -105,7 +105,9 @@ SCUT <- function(data, cls_col, oversample = oversample_smote, #' @importFrom parallel detectCores mclapply #' #' @examples -#' ret <- SCUT_parallel(wine, "type", ncores = 2, undersample = undersample_kmeans) +#' # SCUT_parallel fires a warning if ncores > 1 on Windows and will run on +#' # one core only. +#' ret <- SCUT_parallel(wine, "type", ncores = 1, undersample = undersample_kmeans) #' table(ret$type) SCUT_parallel <- function(data, cls_col, ncores = detectCores() %/% 2, oversample = oversample_smote, @@ -115,8 +117,7 @@ SCUT_parallel <- function(data, cls_col, ncores = detectCores() %/% 2, # windows does not support mclapply, so we have to do this serially if (.Platform$OS.type == "windows") { - warning("SCUT_parallel is not supported on Windows and will run on - one core.") + warning("SCUT_parallel runs on one core only on Windows.") ncores <- 1 } diff --git a/man/SCUT.Rd b/man/SCUT.Rd index ea25b3c..ab64a7f 100644 --- a/man/SCUT.Rd +++ b/man/SCUT.Rd @@ -43,7 +43,7 @@ SCUT_parallel( A dataframe with equal class distribution. } \description{ -This function balances multiclass training datasets. In a dataframe with \code{n} classes and \code{m} rows, the resulting dataframe will have \code{m / n} rows per class. \code{\link{SCUT_parallel}()} distributes each over/undersampling task across multiple cores. Speedup usually occurs only if there are many classes using one of the slower resampling techniques (e.g. \code{\link{undersample_mclust}()}). +This function balances multiclass training datasets. In a dataframe with \code{n} classes and \code{m} rows, the resulting dataframe will have \code{m / n} rows per class. \code{\link{SCUT_parallel}()} distributes each over/undersampling task across multiple cores. Speedup usually occurs only if there are many classes using one of the slower resampling techniques (e.g. \code{\link{undersample_mclust}()}). Note that \code{\link{SCUT_parallel}()} will always run on one core on Windows. } \details{ Custom functions can be used to perform under/oversampling (see the required signature below). Parameters represented by \code{...} should be passsed via \code{osamp_opts} or \code{usamp_opts} as a list. @@ -54,7 +54,9 @@ ret <- SCUT(iris, "Species", undersample = undersample_hclust, ret2 <- SCUT(chickwts, "feed", undersample = undersample_kmeans) table(ret$Species) table(ret2$feed) -ret <- SCUT_parallel(wine, "type", ncores = 2, undersample = undersample_kmeans) +# SCUT_parallel fires a warning if ncores > 1 on Windows and will run on +# one core only. +ret <- SCUT_parallel(wine, "type", ncores = 1, undersample = undersample_kmeans) table(ret$type) } \references{ diff --git a/tests/testthat/test-scut.R b/tests/testthat/test-scut.R index 1066a19..9ae4ca9 100644 --- a/tests/testthat/test-scut.R +++ b/tests/testthat/test-scut.R @@ -28,10 +28,7 @@ for (i in 1:length(undersamplers)) { test_that(paste(osamp, usamp, "(parallel) have equal class distribution"), { - # During R CMD check, doParallel sometimes fails to export the - # package to parallel workers on Windows. This is not a problem - # once the package is installed, so the parallel version is - # skipped on Windows. + # Skip to avoid triggering a warning on > 1 core skip_on_os("windows") @@ -52,7 +49,7 @@ for (i in 1:length(undersamplers)) { if (.Platform$OS.type == "windows") { expect_warning( SCUT_parallel(wine, "type"), - regexp="" + regexp="SCUT_parallel runs on one core only on Windows." ) }