diff --git a/R/dig.R b/R/dig.R index 3dffd85..896634f 100644 --- a/R/dig.R +++ b/R/dig.R @@ -178,7 +178,7 @@ #' is reached, generation of further conditions stops. Use a positive #' integer to enable early stopping; set to `Inf` to remove the cap. #' @param verbose Logical; if `TRUE`, print progress messages. -#' @param threads Number of threads for parallel computation. +#' @param threads (Deprecated.) Number of threads for parallel computation. #' @param error_context A list of details to be used when constructing error #' messages. This is mainly useful when `dig()` is called from another #' function and errors should refer to the caller’s argument names rather @@ -281,7 +281,7 @@ dig <- function(x, t_norm = "goguen", max_results = Inf, verbose = FALSE, - threads = 1L, + threads = deprecated(), error_context = list(arg_x = "x", arg_f = "f", arg_condition = "condition", @@ -316,6 +316,15 @@ dig <- function(x, do.call(f, l) } + if (lifecycle::is_present(threads) && + (is.null(error_context$deprecate_threads) || isTRUE(error_context$deprecate_threads))) { + deprecate_warn(when = "2.3.0", + what = "nuggets::dig(threads)", + details = "The `threads` argument is deprecated and will be removed in future versions.") + } else if (!lifecycle::is_present(threads)) { + threads <- 1L + } + .dig(x = x, xname = deparse(substitute(x)), call_function = "dig", diff --git a/R/dig_associations.R b/R/dig_associations.R index a736712..e346f26 100644 --- a/R/dig_associations.R +++ b/R/dig_associations.R @@ -120,7 +120,8 @@ #' to set `max_results` to a reasonable positive value. Setting `max_results` #' to `Inf` will generate all possible conditions. #' @param verbose a logical value indicating whether to print progress messages. -#' @param threads the number of threads to use for parallel computation. +#' @param threads (Deprecated.) the number of threads to use for parallel +#' computation. #' @param error_context a named list providing context for error messages. #' This is mainly useful when `dig_associations()` is called from another #' function and you want error messages to refer to the argument names @@ -172,7 +173,7 @@ dig_associations <- function(x, t_norm = "goguen", max_results = Inf, verbose = FALSE, - threads = 1, + threads = deprecated(), error_context = list(arg_x = "x", arg_antecedent = "antecedent", arg_consequent = "consequent", @@ -217,6 +218,7 @@ dig_associations <- function(x, } else { contingency_table <- TRUE } + .must_be_flag(contingency_table, arg = error_context$arg_contingency_table, call = error_context$call) @@ -239,6 +241,15 @@ dig_associations <- function(x, antecedent <- enquo(antecedent) consequent <- enquo(consequent) + if (lifecycle::is_present(threads) && + (is.null(error_context$deprecate_threads) || isTRUE(error_context$deprecate_threads))) { + deprecate_warn(when = "2.3.0", + what = "nuggets::dig_associations(threads)", + details = "The `threads` argument is deprecated and will be removed in future versions.") + } else if (!lifecycle::is_present(threads)) { + threads <- 1L + } + res <- .dig(x = x, xname = deparse(substitute(x)), call_function = "dig_associations", diff --git a/R/dig_baseline_contrasts.R b/R/dig_baseline_contrasts.R index affe90f..7195000 100644 --- a/R/dig_baseline_contrasts.R +++ b/R/dig_baseline_contrasts.R @@ -116,7 +116,8 @@ #' to set `max_results` to a reasonable positive value. Setting `max_results` #' to `Inf` will generate all possible conditions. #' @param verbose a logical scalar indicating whether to print progress messages. -#' @param threads the number of threads to use for parallel computation. +#' @param threads (Deprecated.) the number of threads to use for parallel +#' computation. #' @return An S3 object which is an instance of `baseline_contrasts` and `nugget` #' classes and which is a tibble with found patterns in rows. The following #' columns are always present: @@ -179,7 +180,7 @@ dig_baseline_contrasts <- function(x, wilcox_digits_rank = Inf, max_results = Inf, verbose = FALSE, - threads = 1) { + threads = deprecated()) { .must_be_enum(method, c("t", "wilcox")) .must_be_enum(alternative, c("two.sided", "less", "greater")) .must_be_double_scalar(h0) @@ -225,6 +226,12 @@ dig_baseline_contrasts <- function(x, stop("Internal error - unknown method: ", method) } + if (lifecycle::is_present(threads)) { + deprecate_warn(when = "2.3.0", + what = "nuggets::dig_baseline_contrasts(threads)", + details = "The `threads` argument is deprecated and will be removed in future versions.") + } + res <- dig_grid(x = x, f = f, condition = !!condition, @@ -255,6 +262,7 @@ dig_baseline_contrasts <- function(x, arg_max_results = "max_results", arg_verbose = "verbose", arg_threads = "threads", + deprecate_threads = FALSE, call = current_env())) digattr <- attributes(res) diff --git a/R/dig_complement_contrasts.R b/R/dig_complement_contrasts.R index 861afbb..cdc1a4f 100644 --- a/R/dig_complement_contrasts.R +++ b/R/dig_complement_contrasts.R @@ -127,7 +127,8 @@ #' to set `max_results` to a reasonable positive value. Setting `max_results` #' to `Inf` will generate all possible conditions. #' @param verbose a logical scalar indicating whether to print progress messages. -#' @param threads the number of threads to use for parallel computation. +#' @param threads (Deprecated.) the number of threads to use for parallel +#' computation. #' @return An S3 object which is an instance of `complement_contrasts` and `nugget` #' classes and which is a tibble with found patterns in rows. The following #' columns are always present: @@ -194,7 +195,7 @@ dig_complement_contrasts <- function(x, wilcox_digits_rank = Inf, max_results = Inf, verbose = FALSE, - threads = 1L) { + threads = deprecated()) { .must_be_enum(method, c("t", "wilcox", "var")) .must_be_enum(alternative, c("two.sided", "less", "greater")) .must_be_double_scalar(h0) @@ -252,6 +253,12 @@ dig_complement_contrasts <- function(x, stop("Internal error - unknown method: ", method) } + if (lifecycle::is_present(threads)) { + deprecate_warn(when = "2.3.0", + what = "nuggets::dig_complement_contrasts(threads)", + details = "The `threads` argument is deprecated and will be removed in future versions.") + } + res <- dig_grid(x = x, f = f, condition = !!condition, @@ -282,6 +289,7 @@ dig_complement_contrasts <- function(x, arg_max_results = "max_results", arg_verbose = "verbose", arg_threads = "threads", + deprecate_threads = FALSE, call = current_env())) digattr <- attributes(res) diff --git a/R/dig_correlations.R b/R/dig_correlations.R index 399c383..71f39ff 100644 --- a/R/dig_correlations.R +++ b/R/dig_correlations.R @@ -93,7 +93,8 @@ #' to set `max_results` to a reasonable positive value. Setting `max_results` #' to `Inf` will generate all possible conditions. #' @param verbose a logical scalar indicating whether to print progress messages. -#' @param threads the number of threads to use for parallel computation. +#' @param threads (Deprecated.) the number of threads to use for parallel +#' computation. #' @return An S3 object which is an instance of `correlations` and `nugget` #' classes and which is tibble with found patterns. #' The `nugget` object also contains metadata about the search @@ -134,7 +135,7 @@ dig_correlations <- function(x, max_support = 1.0, max_results = Inf, verbose = FALSE, - threads = 1) { + threads = deprecated()) { .must_be_enum(method, c("pearson", "kendall", "spearman")) .must_be_enum(alternative, c("two.sided", "less", "greater")) .must_be_flag(exact, null = TRUE) @@ -156,6 +157,12 @@ dig_correlations <- function(x, n = nrow(pd))) } + if (lifecycle::is_present(threads)) { + deprecate_warn(when = "2.3.0", + what = "nuggets::dig_correlations(threads)", + details = "The `threads` argument is deprecated and will be removed in future versions.") + } + res <- dig_grid(x = x, f = f, condition = !!condition, @@ -185,6 +192,7 @@ dig_correlations <- function(x, arg_max_results = "max_results", arg_verbose = "verbose", arg_threads = "threads", + deprecate_threads = FALSE, call = current_env())) digattr <- attributes(res) diff --git a/R/dig_grid.R b/R/dig_grid.R index a8ba319..d8ae918 100644 --- a/R/dig_grid.R +++ b/R/dig_grid.R @@ -123,7 +123,8 @@ #' to set `max_results` to a reasonable positive value. Setting `max_results` #' to `Inf` will generate all possible conditions. #' @param verbose a logical scalar indicating whether to print progress messages. -#' @param threads the number of threads to use for parallel computation. +#' @param threads (Deprecated.) the number of threads to use for parallel +#' computation. #' @param error_context a list of details to be used in error messages. #' This argument is useful when `dig_grid()` is called from another #' function to provide error messages, which refer to arguments of the @@ -203,7 +204,7 @@ dig_grid <- function(x, max_support = 1.0, max_results = Inf, verbose = FALSE, - threads = 1L, + threads = deprecated(), error_context = list(arg_x = "x", arg_f = "f", arg_condition = "condition", @@ -335,6 +336,15 @@ dig_grid <- function(x, callbackF <- tempF3 } + if (lifecycle::is_present(threads) && + (is.null(error_context$deprecate_threads) || isTRUE(error_context$deprecate_threads))) { + deprecate_warn(when = "2.3.0", + what = "nuggets::dig_grid(threads)", + details = "The `threads` argument is deprecated and will be removed in future versions.") + } else if (!lifecycle::is_present(threads)) { + threads <- 1L + } + res <- dig(x = x, f = callbackF, condition = !!condition, @@ -358,6 +368,7 @@ dig_grid <- function(x, arg_max_results = error_context$arg_max_results, arg_verbose = error_context$arg_verbose, arg_threads = error_context$arg_threads, + deprecate_threads = FALSE, call = error_context$call)) digattr <- attributes(res) res <- do.call(bind_rows, res) @@ -385,4 +396,3 @@ dig_grid <- function(x, verbose = digattr$call_args$verbose, threads = digattr$call_args$threads)) } - diff --git a/R/dig_paired_baseline_contrasts.R b/R/dig_paired_baseline_contrasts.R index 5075d2c..74ffc9e 100644 --- a/R/dig_paired_baseline_contrasts.R +++ b/R/dig_paired_baseline_contrasts.R @@ -128,7 +128,8 @@ #' to set `max_results` to a reasonable positive value. Setting `max_results` #' to `Inf` will generate all possible conditions. #' @param verbose a logical scalar indicating whether to print progress messages. -#' @param threads the number of threads to use for parallel computation. +#' @param threads (Deprecated.) the number of threads to use for parallel +#' computation. #' @return An S3 object which is an instance of `paired_baseline_contrasts` #' and `nugget` classes and which is a tibble with found patterns in rows. #' The following columns are always present: @@ -203,7 +204,7 @@ dig_paired_baseline_contrasts <- function(x, wilcox_digits_rank = Inf, max_results = Inf, verbose = FALSE, - threads = 1) { + threads = deprecated()) { .must_be_enum(method, c("t", "wilcox")) .must_be_enum(alternative, c("two.sided", "less", "greater")) .must_be_double_scalar(h0) @@ -252,6 +253,12 @@ dig_paired_baseline_contrasts <- function(x, stop("Internal error - unknown method: ", method) } + if (lifecycle::is_present(threads)) { + deprecate_warn(when = "2.3.0", + what = "nuggets::dig_paired_baseline_contrasts(threads)", + details = "The `threads` argument is deprecated and will be removed in future versions.") + } + res <- dig_grid(x = x, f = f, condition = !!condition, @@ -282,6 +289,7 @@ dig_paired_baseline_contrasts <- function(x, arg_max_results = "max_results", arg_verbose = "verbose", arg_threads = "threads", + deprecate_threads = FALSE, call = current_env())) digattr <- attributes(res) diff --git a/R/dig_tautologies.R b/R/dig_tautologies.R index 693e870..630986f 100644 --- a/R/dig_tautologies.R +++ b/R/dig_tautologies.R @@ -75,7 +75,8 @@ #' to set `max_results` to a reasonable positive value. Setting `max_results` #' to `Inf` will generate all possible conditions. #' @param verbose a logical value indicating whether to print progress messages. -#' @param threads the number of threads to use for parallel computation. +#' @param threads (Deprecated.) the number of threads to use for parallel +#' computation. #' @returns An S3 object which is an instance of `associations` and `nugget` #' classes and which is a tibble with found tautologies in the format equal #' to the output of [dig_associations()]. @@ -100,7 +101,7 @@ dig_tautologies <- function(x, t_norm = "goguen", max_results = Inf, verbose = FALSE, - threads = 1) { + threads = deprecated()) { .must_be_integerish_scalar(max_length) .must_be_greater_eq(max_length, 0) @@ -126,6 +127,12 @@ dig_tautologies <- function(x, max_length <- sum(ante_cols$selected) } + if (lifecycle::is_present(threads)) { + deprecate_warn(when = "2.3.0", + what = "nuggets::dig_tautologies(threads)", + details = "The `threads` argument is deprecated and will be removed in future versions.") + } + digattr <- NULL while (len <= max_length) { maxres <- max_results @@ -163,6 +170,7 @@ dig_tautologies <- function(x, arg_max_results = "internal `maxres`", arg_verbose = "verbose", arg_threads = "threads", + deprecate_threads = FALSE, call = current_env())) if (is.null(digattr)) { @@ -195,5 +203,5 @@ dig_tautologies <- function(x, t_norm = t_norm, max_results = max_results, verbose = verbose, - threads = threads)) + threads = digattr$call_args$threads)) } diff --git a/tests/testthat/test-dig_associations.R b/tests/testthat/test-dig_associations.R index 2c37fb7..97da66e 100644 --- a/tests/testthat/test-dig_associations.R +++ b/tests/testthat/test-dig_associations.R @@ -389,8 +389,7 @@ test_that("dig_associations return object details", { min_support = 0.3, min_confidence = 0.5, t_norm = "lukas", - max_results = 10, - threads = 1) + max_results = 10) expect_true(is_nugget(res, "associations")) expect_true(is_tibble(res)) @@ -413,7 +412,6 @@ test_that("dig_associations return object details", { expect_equal(attr(res, "call_args")$contingency_table, TRUE) expect_equal(attr(res, "call_args")$t_norm, "lukas") expect_equal(attr(res, "call_args")$max_results, 10) - expect_equal(attr(res, "call_args")$threads, 1) expect_true(is_tibble(res)) }) @@ -452,8 +450,6 @@ test_that("dig_associations errors", { "`max_results` must be an integerish scalar.") expect_error(dig_associations(d, verbose = "x"), "`verbose` must be a flag.") - expect_error(dig_associations(d, threads = "x"), - "`threads` must be an integerish scalar.") }) test_that("dig_associations return nothing", { @@ -470,8 +466,7 @@ test_that("dig_associations return nothing", { min_confidence = 0.2, t_norm = "lukas", max_results = 5, - verbose = FALSE, - threads = 1) + verbose = FALSE) expect_true(is_nugget(res, "associations")) expect_true(is_tibble(res)) diff --git a/tests/testthat/test-dig_baseline_contrasts.R b/tests/testthat/test-dig_baseline_contrasts.R index 8664331..a5fd953 100644 --- a/tests/testthat/test-dig_baseline_contrasts.R +++ b/tests/testthat/test-dig_baseline_contrasts.R @@ -97,8 +97,7 @@ test_that("dig_baseline_contrasts call args", { wilcox_tol_root = 1e-3, wilcox_digits_rank = 5, max_results = 100, - verbose = TRUE, - threads = 1)) + verbose = TRUE)) expect_true(is_nugget(res, flavour = "baseline_contrasts")) expect_true(is_tibble(res)) @@ -138,7 +137,6 @@ test_that("dig_baseline_contrasts call args", { expect_equal(attr(res, "call_args")$wilcox_digits_rank, 5) expect_equal(attr(res, "call_args")$max_results, 100) expect_equal(attr(res, "call_args")$verbose, TRUE) - expect_equal(attr(res, "call_args")$threads, 1L) }) test_that("dig_baseline_contrasts errors", { diff --git a/tests/testthat/test-dig_complement_contrasts.R b/tests/testthat/test-dig_complement_contrasts.R index 171ce16..099960a 100644 --- a/tests/testthat/test-dig_complement_contrasts.R +++ b/tests/testthat/test-dig_complement_contrasts.R @@ -98,8 +98,7 @@ test_that("dig_complement_contrasts call args", { wilcox_tol_root = 1e-3, wilcox_digits_rank = 5, max_results = 5, - verbose = TRUE, - threads = 1)) + verbose = TRUE)) expect_true(is_nugget(res, flavour = "complement_contrasts")) expect_true(is_tibble(res)) @@ -137,7 +136,6 @@ test_that("dig_complement_contrasts call args", { expect_equal(attr(res, "call_args")$wilcox_digits_rank, 5) expect_equal(attr(res, "call_args")$max_results, 5) expect_equal(attr(res, "call_args")$verbose, TRUE) - expect_equal(attr(res, "call_args")$threads, 1L) }) test_that("dig_paired contrasts errors", { diff --git a/tests/testthat/test-dig_correlations.R b/tests/testthat/test-dig_correlations.R index acff342..7b84f8f 100644 --- a/tests/testthat/test-dig_correlations.R +++ b/tests/testthat/test-dig_correlations.R @@ -146,8 +146,7 @@ test_that("dig_correlations call args", { min_support = 0.1, max_support = 0.9, max_results = 100, - verbose = TRUE, - threads = 1)) + verbose = TRUE)) expect_true(is_nugget(res, flavour = "correlations")) expect_true(is_tibble(res)) expect_equal(attr(res, "call_function"), "dig_correlations") @@ -171,7 +170,6 @@ test_that("dig_correlations call args", { expect_equal(attr(res, "call_args")$max_support, 0.9) expect_equal(attr(res, "call_args")$max_results, 100) expect_equal(attr(res, "call_args")$verbose, TRUE) - expect_equal(attr(res, "call_args")$threads, 1) }) diff --git a/tests/testthat/test-dig_grid.R b/tests/testthat/test-dig_grid.R index c53d217..411c399 100644 --- a/tests/testthat/test-dig_grid.R +++ b/tests/testthat/test-dig_grid.R @@ -554,8 +554,7 @@ test_that("dig_grid call args", { min_support = 0.1, max_support = 0.9, max_results = 100L, - verbose = TRUE, - threads = 1L)) + verbose = TRUE)) expect_true(is_nugget(res)) expect_true(is_tibble(res)) @@ -580,7 +579,6 @@ test_that("dig_grid call args", { expect_equal(attr(res, "call_args")$max_support, 0.9) expect_equal(attr(res, "call_args")$max_results, 100L) expect_equal(attr(res, "call_args")$verbose, TRUE) - expect_equal(attr(res, "call_args")$threads, 1L) }) test_that("errors", { @@ -623,8 +621,6 @@ test_that("errors", { "`max_length` must be an integerish scalar") expect_error(dig_grid(d, f = fb, type = "crisp", condition = l, min_support = "x"), "`min_support` must be a double scalar") - expect_error(dig_grid(d, f = fb, type = "crisp", condition = l, threads = "x"), - "`threads` must be an integerish scalar") expect_error(dig_grid(d, f = fb, disjoint = list("x")), "`disjoint` must be a plain vector") diff --git a/tests/testthat/test-dig_paired_baseline_contrasts.R b/tests/testthat/test-dig_paired_baseline_contrasts.R index 7395614..68267f3 100644 --- a/tests/testthat/test-dig_paired_baseline_contrasts.R +++ b/tests/testthat/test-dig_paired_baseline_contrasts.R @@ -105,8 +105,8 @@ test_that("dig_paired_baseline_contrasts call args", { wilcox_tol_root = 1e-3, wilcox_digits_rank = 5, max_results = 100, - verbose = TRUE, - threads = 1)) + verbose = TRUE)) + expect_true(is_nugget(res, flavour = "paired_baseline_contrasts")) expect_true(is_tibble(res)) @@ -148,7 +148,6 @@ test_that("dig_paired_baseline_contrasts call args", { expect_equal(attr(res, "call_args")$wilcox_digits_rank, 5) expect_equal(attr(res, "call_args")$max_results, 100) expect_equal(attr(res, "call_args")$verbose, TRUE) - expect_equal(attr(res, "call_args")$threads, 1L) }) test_that("dig_paired contrasts errors", { diff --git a/tests/testthat/test-dig_tautologies.R b/tests/testthat/test-dig_tautologies.R index 9385431..2fd79a1 100644 --- a/tests/testthat/test-dig_tautologies.R +++ b/tests/testthat/test-dig_tautologies.R @@ -181,8 +181,7 @@ test_that("dig_tautologies argument forwarding and attributes", { min_confidence = 0.2, t_norm = "lukas", max_results = 5, - verbose = FALSE, - threads = 1 + verbose = FALSE ) ) @@ -235,6 +234,4 @@ test_that("dig_tautologies handles invalid arguments", { "`max_results` must be an integerish scalar.") expect_error(dig_tautologies(d, verbose = "x"), "`verbose` must be a flag.") - expect_error(dig_tautologies(d, threads = "x"), - "`threads` must be an integerish scalar.") })