-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#' @title Set a seed to run a target. | ||
#' @export | ||
#' @family seeds | ||
#' @description `targets` generates its own target-specific seeds | ||
#' using [tar_seed_create()]. Use [tar_seed_set()] to set one of | ||
#' these seeds in R. | ||
#' @details [tar_seed_set()] gives the user-supplied `seed` to | ||
#' `set.seed()` and sets arguments `kind = "default"`, | ||
#' `normal.kind = "default"`, and `sample.kind = "default"`. | ||
#' @return `NULL` (invisibly). | ||
#' @param seed Integer of length 1, value of the seed to set | ||
#' with `set.seed()`. | ||
#' @examples | ||
#' seed <- tar_seed_create() | ||
#' seed | ||
#' sample(10) | ||
#' tar_seed_set(seed) | ||
#' sample(10) | ||
#' tar_seed_set(seed) | ||
#' sample(10) | ||
tar_seed_set <- function(seed) { | ||
if (!is.null(seed) && !anyNA(seed)) { | ||
set.seed( | ||
seed = seed, | ||
kind = "default", | ||
normal.kind = "default", | ||
sample.kind = "default" | ||
) | ||
} | ||
invisible() | ||
} |
This file was deleted.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
tar_test("tar_seed_set()", { | ||
out <- list() | ||
tar_seed_set(0L) | ||
out[[1L]] <- runif(n = 1L) | ||
tar_seed_set(NA) | ||
out[[2L]] <- runif(n = 1L) | ||
tar_seed_set(NULL) | ||
out[[3L]] <- runif(n = 1L) | ||
tar_seed_set(2L) | ||
out[[4L]] <- runif(n = 1L) | ||
tar_seed_set(2L) | ||
out[[5L]] <- runif(n = 1L) | ||
tar_seed_set(3L) | ||
out[[6L]] <- runif(n = 1L) | ||
expect_equal(out[[4L]], out[[5L]]) | ||
out[[5L]] <- NULL | ||
for (i in seq_len(5L)) { | ||
for (j in seq_len(5L)) { | ||
if (i != j) { | ||
expect_false(out[[i]] == out[[j]]) | ||
} | ||
} | ||
} | ||
}) |