diff --git a/CRAN-SUBMISSION b/CRAN-SUBMISSION index 349efe0..5b3fd4c 100644 --- a/CRAN-SUBMISSION +++ b/CRAN-SUBMISSION @@ -1,3 +1,3 @@ -Version: 0.3.4 -Date: 2022-04-19 07:36:07 UTC -SHA: 7069dbd5ba09a7199386c2691768f135fc407183 +Version: 0.3.5 +Date: 2022-08-27 20:16:58 UTC +SHA: a22572c46cf5291dc364afc5415806ca30b5814e diff --git a/DESCRIPTION b/DESCRIPTION index 0d9354a..fc97769 100755 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: tglkmeans Title: Efficient Implementation of K-Means++ Algorithm -Version: 0.3.4 +Version: 0.3.5 Authors@R: c(person(given = "Aviezer", family = "Lifshitz", @@ -35,10 +35,11 @@ Suggests: knitr, rlang, rmarkdown, - testthat + testthat, + withr LinkingTo: Rcpp -VignetteBuilder: +VignetteBuilder: knitr Encoding: UTF-8 NeedsCompilation: yes diff --git a/NEWS.md b/NEWS.md index 9fa0773..d325c24 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,10 +1,12 @@ -# tglkmeans (development version) +# tglkmeans 0.3.5 * Changed errors from cpp to 1 based indexing. +* fix: loading the package failed on machines with a single core. # tglkmeans 0.3.4 * First CRAN release. + # tglkmeans 0.3.3 * Set NA values to zeros in correlation matrix when reordering clusters diff --git a/R/misc.R b/R/misc.R index 607a673..eb22ffe 100755 --- a/R/misc.R +++ b/R/misc.R @@ -10,7 +10,7 @@ #' } #' @export tglkmeans.set_parallel <- function(thread_num) { - if (1 == thread_num) { + if (thread_num <= 1) { options(tglkmeans.parallel = FALSE) } else { doFuture::registerDoFuture() diff --git a/R/zzz.R b/R/zzz.R index 5b2d5b2..1385578 100755 --- a/R/zzz.R +++ b/R/zzz.R @@ -1,5 +1,5 @@ .onLoad <- function(libname, pkgname) { - tglkmeans.set_parallel(round(parallel::detectCores() / 2)) + tglkmeans.set_parallel(pmax(1, round(parallel::detectCores() / 2))) utils::suppressForeignCheck(c("clust", "new_clust", "true_clust", "intra_clust_order", "idx")) utils::globalVariables(c("clust", "new_clust", "true_clust", "intra_clust_order", "idx")) } diff --git a/cran-comments.md b/cran-comments.md index 0a20e4d..6c48d62 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -2,11 +2,7 @@ 0 errors | 0 warnings | 0 notes -## DESCRIPTION changes +# Fix -* Added Weizmann Institute of Science as cph -* Added references of the original algorithm to the description part. +* loading the package failed on machines with a single core. -## Regarding the use of cores in the examples - -* Added \donttest clause wrapping `tglmeans.set_parallel` examples section. The other examples work with a single core. diff --git a/tests/testthat/test-misc.R b/tests/testthat/test-misc.R index 2949338..9faaa45 100644 --- a/tests/testthat/test-misc.R +++ b/tests/testthat/test-misc.R @@ -10,12 +10,30 @@ test_that("onLoad does not fail", { }) context("number of threads") -test_that("parallel is turned off when number of threads is 1", { - tglkmeans.set_parallel(1) - expect_false(getOption("tglkmeans.parallel")) +test_that("parallel is turned off when number of threads <= 1", { + withr::with_options( + list(tglkmeans.parallel = TRUE), + { + tglkmeans.set_parallel(1) + expect_false(getOption("tglkmeans.parallel")) + } + ) + + withr::with_options( + list(tglkmeans.parallel = TRUE), + { + tglkmeans.set_parallel(0) + expect_false(getOption("tglkmeans.parallel")) + } + ) }) test_that("parallel is turned on when number of threads is not 1", { - tglkmeans.set_parallel(2) - expect_true(getOption("tglkmeans.parallel")) + withr::with_options( + list(tglkmeans.parallel = FALSE), + { + tglkmeans.set_parallel(2) + expect_true(getOption("tglkmeans.parallel")) + } + ) })