Skip to content

Commit

Permalink
add disclaimer for ncores on Windows in tests, prevent SCUT_parallel …
Browse files Browse the repository at this point in the history
…example from triggering a warning
  • Loading branch information
s-kganz committed Jun 24, 2021
1 parent 09a475c commit e5f2da8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
7 changes: 4 additions & 3 deletions R/scut.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
}

Expand Down
6 changes: 4 additions & 2 deletions man/SCUT.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 2 additions & 5 deletions tests/testthat/test-scut.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")


Expand All @@ -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."
)
}

Expand Down

0 comments on commit e5f2da8

Please sign in to comment.