Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions R/dig.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
15 changes: 13 additions & 2 deletions R/dig_associations.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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)
Expand All @@ -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",
Expand Down
12 changes: 10 additions & 2 deletions R/dig_baseline_contrasts.R
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)

Expand Down
12 changes: 10 additions & 2 deletions R/dig_complement_contrasts.R
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)

Expand Down
12 changes: 10 additions & 2 deletions R/dig_correlations.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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,
Expand Down Expand Up @@ -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)

Expand Down
16 changes: 13 additions & 3 deletions R/dig_grid.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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,
Expand All @@ -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)
Expand Down Expand Up @@ -385,4 +396,3 @@ dig_grid <- function(x,
verbose = digattr$call_args$verbose,
threads = digattr$call_args$threads))
}

12 changes: 10 additions & 2 deletions R/dig_paired_baseline_contrasts.R
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)

Expand Down
14 changes: 11 additions & 3 deletions R/dig_tautologies.R
Original file line number Diff line number Diff line change
Expand Up @@ -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()].
Expand All @@ -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)

Expand All @@ -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
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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))
}
9 changes: 2 additions & 7 deletions tests/testthat/test-dig_associations.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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))
})

Expand Down Expand Up @@ -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", {
Expand All @@ -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))
Expand Down
4 changes: 1 addition & 3 deletions tests/testthat/test-dig_baseline_contrasts.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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", {
Expand Down
Loading