From f3365341e0dcdc5b5c71bcdf40b6ba67b4882e84 Mon Sep 17 00:00:00 2001 From: wlandau Date: Sun, 24 Sep 2023 09:04:30 -0400 Subject: [PATCH] Migrate testing --- DESCRIPTION | 2 +- NEWS.md | 2 +- R/class_builder.R | 4 +--- R/class_cue.R | 21 +++------------------ R/tar_cue.R | 25 +++++++++++++++---------- man/tar_cue.Rd | 11 +++++------ tests/testthat/test-class_cue.R | 15 --------------- tests/testthat/test-tar_cue.R | 4 ++++ 8 files changed, 30 insertions(+), 54 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index e4a3f0d2a..6ca455e57 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -12,7 +12,7 @@ Description: Pipeline tools coordinate the pieces of computationally The methodology in this package borrows from GNU 'Make' (2015, ISBN:978-9881443519) and 'drake' (2018, ). -Version: 1.3.0.9001 +Version: 1.3.0.9002 License: MIT + file LICENSE URL: https://docs.ropensci.org/targets/, https://github.com/ropensci/targets BugReports: https://github.com/ropensci/targets/issues diff --git a/NEWS.md b/NEWS.md index bb9036f75..29a1e541d 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,4 @@ -# targets 1.3.0.9001 (development) +# targets 1.3.0.9002 (development) * Add `tar_config_projects()` and `tar_config_yaml()` (#1153, @psychelzh). * Apply error modes to `builder_wait_correct_hash()` in `target_conclude.tar_builder()` (#1154, @gadenbuie). diff --git a/R/class_builder.R b/R/class_builder.R index 03c63c453..47af730c9 100644 --- a/R/class_builder.R +++ b/R/class_builder.R @@ -94,7 +94,6 @@ builder_should_run <- function(target, meta) { if (cue_format(cue, target, meta, record)) return(TRUE) if (cue_repository(cue, target, meta, record)) return(TRUE) if (cue_iteration(cue, target, meta, record)) return(TRUE) - if (cue_seed(cue, target, meta, record)) return(TRUE) if (cue_file(cue, target, meta, record)) return(TRUE) FALSE } @@ -527,7 +526,6 @@ builder_sitrep <- function(target, meta) { NA, cue_iteration(cue, target, meta, record) ), - file = if_any(cue_record, NA, cue_file(cue, target, meta, record)), - seed = if_any(cue_record, NA, cue_seed(cue, target, meta, record)) + file = if_any(cue_record, NA, cue_file(cue, target, meta, record)) ) } diff --git a/R/class_cue.R b/R/class_cue.R index ff20cf502..7db8182aa 100644 --- a/R/class_cue.R +++ b/R/class_cue.R @@ -5,8 +5,7 @@ cue_init <- function( format = TRUE, repository = TRUE, iteration = TRUE, - file = TRUE, - seed = TRUE + file = TRUE ) { cue_new( mode = mode, @@ -15,8 +14,7 @@ cue_init <- function( format = format, repository = repository, iteration = iteration, - file = file, - seed = seed + file = file ) } @@ -27,8 +25,7 @@ cue_new <- function( format = NULL, repository = NULL, iteration = NULL, - file = NULL, - seed = NULL + file = NULL ) { force(mode) force(command) @@ -37,7 +34,6 @@ cue_new <- function( force(repository) force(iteration) force(file) - force(seed) enclass(environment(), "tar_cue") } @@ -132,15 +128,6 @@ cue_file <- function(cue, target, meta, record) { !store_has_correct_hash(target$store) } -cue_seed <- function(cue, target, meta, record) { - if (!cue$seed) { - return(FALSE) - } - old <- as.integer(record$seed) - new <- as.integer(target$command$seed) - anyNA(new) || !identical(old, new) -} - cue_validate <- function(cue) { tar_assert_correct_fields(cue, cue_new) tar_assert_chr(cue$mode) @@ -151,7 +138,6 @@ cue_validate <- function(cue) { tar_assert_lgl(cue$repository) tar_assert_lgl(cue$iteration) tar_assert_lgl(cue$file) - tar_assert_lgl(cue$seed) tar_assert_scalar(cue$mode) tar_assert_scalar(cue$command) tar_assert_scalar(cue$depend) @@ -159,7 +145,6 @@ cue_validate <- function(cue) { tar_assert_scalar(cue$repository) tar_assert_scalar(cue$iteration) tar_assert_scalar(cue$file) - tar_assert_scalar(cue$seed) } #' @export diff --git a/R/tar_cue.R b/R/tar_cue.R index 9d35ce96e..239e051d3 100644 --- a/R/tar_cue.R +++ b/R/tar_cue.R @@ -84,11 +84,10 @@ #' [tar_target()] or [tar_option_set()]. #' @param file Logical, whether to rerun the target if the file(s) with the #' return value changed or at least one is missing. -#' @param seed Logical, whether to rerun the target if pseudo-random -#' number generator seed either changed or is `NA`. -#' The reproducible deterministic target-specific -#' seeds are controlled by `tar_option_get("seed")` and the target names. -#' See [tar_option_set()] for details. +#' @param seed Deprecated in version 1.3.0.9002 on 2023-09-24. +#' For details on how `targets` handles +#' pseudo-random numbers, please see +#' . #' @examples #' # The following target will always run when the pipeline runs. #' x <- tar_target(x, download_data(), cue = tar_cue(mode = "always")) @@ -100,7 +99,7 @@ tar_cue <- function( repository = TRUE, iteration = TRUE, file = TRUE, - seed = TRUE + seed = NULL ) { tar_assert_lgl(command) tar_assert_lgl(depend) @@ -108,14 +107,21 @@ tar_cue <- function( tar_assert_lgl(repository) tar_assert_lgl(iteration) tar_assert_lgl(file) - tar_assert_lgl(seed) tar_assert_scalar(command) tar_assert_scalar(depend) tar_assert_scalar(format) tar_assert_scalar(repository) tar_assert_scalar(iteration) tar_assert_scalar(file) - tar_assert_scalar(seed) + if (!is.null(seed)) { + tar_warn_deprecate( + "The seed argument of tar_cue() was deprecated ", + "in {targets} version 1.3.0.9002 on 2023-09-24. ", + "For details on how `targets` handles ", + "pseudo-random numbers, please see ", + "https://books.ropensci.org/targets/random.html" + ) + } cue_init( mode = match.arg(mode), command = command, @@ -123,7 +129,6 @@ tar_cue <- function( format = format, repository = repository, iteration = iteration, - file = file, - seed = seed + file = file ) } diff --git a/man/tar_cue.Rd b/man/tar_cue.Rd index 17d890253..63abddbaa 100644 --- a/man/tar_cue.Rd +++ b/man/tar_cue.Rd @@ -12,7 +12,7 @@ tar_cue( repository = TRUE, iteration = TRUE, file = TRUE, - seed = TRUE + seed = NULL ) } \arguments{ @@ -42,11 +42,10 @@ iteration method changed. The iteration method is user-specified through \item{file}{Logical, whether to rerun the target if the file(s) with the return value changed or at least one is missing.} -\item{seed}{Logical, whether to rerun the target if pseudo-random -number generator seed either changed or is \code{NA}. -The reproducible deterministic target-specific -seeds are controlled by \code{tar_option_get("seed")} and the target names. -See \code{\link[=tar_option_set]{tar_option_set()}} for details.} +\item{seed}{Deprecated in version 1.3.0.9002 on 2023-09-24. +For details on how \code{targets} handles +pseudo-random numbers, please see +\url{https://books.ropensci.org/targets/random.html}.} } \description{ Declare the rules that mark a target as outdated. diff --git a/tests/testthat/test-class_cue.R b/tests/testthat/test-class_cue.R index f4ae57f97..ee874641d 100644 --- a/tests/testthat/test-class_cue.R +++ b/tests/testthat/test-class_cue.R @@ -318,21 +318,6 @@ tar_test("cue_iteration() suppressed", { expect_equal(out, "x") }) -tar_test("cue_seed() suppressed", { - on.exit(tar_option_reset()) - tar_option_set(seed = NA) - x <- target_init("x", quote(1L)) - local <- local_init(pipeline_init(list(x))) - local$run() - for (index in seq_len(3)) { - x <- target_init("x", quote(1L), cue = tar_cue(seed = FALSE)) - local <- local_init(pipeline_init(list(x))) - local$run() - out <- counter_get_names(local$scheduler$progress$built) - expect_equal(out, character(0)) - } -}) - tar_test("cue_file()", { x <- target_init("x", quote(1L)) local <- local_init(pipeline_init(list(x))) diff --git a/tests/testthat/test-tar_cue.R b/tests/testthat/test-tar_cue.R index ae84d8737..b18d5c071 100644 --- a/tests/testthat/test-tar_cue.R +++ b/tests/testthat/test-tar_cue.R @@ -6,3 +6,7 @@ tar_test("tar_cue() works", { tar_test("tar_cue() takes only allowed modes", { expect_error(tar_cue(mode = "nope")) }) + +tar_test("tar_cue() deprecate seed", { + expect_warning(tar_cue(seed = TRUE), class = "tar_condition_deprecate") +})