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
2 changes: 2 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,5 @@ NEWS\.tex
.*_snaps.*
^Meta$
^CNAME$
^_pkgdown\.yml$
^\.github$
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ Imports:
tools,
graphics,
rlang,
uuid (>= 1.0-3),
knitr (>= 1.19)
Suggests:
testthat (>= 3.0.0),
uuid (>= 1.0-3),
writexl (>= 1.5.0),
glue (>= 1.6.0),
httr (>= 1.4.0),
Expand Down
1 change: 1 addition & 0 deletions R/class_random_block_size_randomizer.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#'
#' @param blockSizes List of block size configurations, each mapping treatment arm IDs to sizes.
#' @param seed Integer random seed used for reproducibility.
#' @param ... Additional arguments (currently unused).
#'
#' @return A `RandomBlockSizeRandomizer` reference class object.
#'
Expand Down
2 changes: 1 addition & 1 deletion R/f_random_stratum_builder.R
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ createStratumId <- function(factorLevels) {
)
}

factorLevel <- factorLevels.get(factorName)
factorLevel <- factorLevels[[factorName]]
if (is.null(factorLevel) || nchar(trimws(factorLevel)) == 0) {
stop("The specified factor level (#", counter, ") is invalid")
}
Expand Down
8 changes: 4 additions & 4 deletions R/f_seed.R
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,11 @@
#' is better than the pseudo-random number algorithms typically used
#' in computer programs. For more information see \url{https://www.random.org}.
#'
#' @seealso \link{getSimulatedTwoArmMeans}
#'
#' @return an integer value or vector containing one or more seeds.
#'
#' @export
#'
createSeed <- function(numberOfValues = 1, minValue = 1000000, maxValue = 9999999, ...) {
.assertPackageIsInstalled("httr")
.assertPackageIsInstalled("glue")
.assertIsSingleInteger(numberOfValues, "numberOfValues", validateType = FALSE)
.assertIsInClosedInterval(numberOfValues, "numberOfValues", lower = 1, upper = 1000)
.assertIsSingleInteger(minValue, "minValue", validateType = FALSE)
Expand All @@ -97,8 +93,12 @@ createSeed <- function(numberOfValues = 1, minValue = 1000000, maxValue = 999999
stop(C_EXCEPTION_TYPE_CONFLICTING_ARGUMENTS, "'minValue' (", minValue, ") ",
"must be smaller than argument 'maxValue'(", maxValue, ")")
}

tryCatch(
{
.assertPackageIsInstalled("httr")
.assertPackageIsInstalled("glue")

args <- list(...)
if (length(args) > 0 && !is.null(args[["test_exception"]])) {
stop(args[["test_exception"]])
Expand Down
3 changes: 0 additions & 3 deletions man/createSeed.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions man/getRandomBlockSizeRandomizer.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions tests/testthat/test_f_seed.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
# ------------------------------------------------------------------------------

test_that("For invalid input arguments 'createSeed' throws meaningful exceptions", {
testthat::skip_if_not_installed("httr")
testthat::skip_if_not_installed("glue")

expect_error(createSeed(numberOfValues = 0),
"Argument out of bounds: 'numberOfValues' (0) is out of bounds [1; 1000]", fixed = TRUE)
expect_error(createSeed(numberOfValues = 1, minValue = -1),
Expand All @@ -32,6 +35,9 @@ test_that("For invalid input arguments 'createSeed' throws meaningful exceptions
})

test_that("The results of 'createSeed' depend on the input arguments as expected", {
testthat::skip_if_not_installed("httr")
testthat::skip_if_not_installed("glue")

expect_length(createSeed(), 1)
expect_length(createSeed(numberOfValues = 9), 9)

Expand All @@ -41,6 +47,9 @@ test_that("The results of 'createSeed' depend on the input arguments as expected
})

test_that("'createSeed' returns valid seed although network connection is missing", {
testthat::skip_if_not_installed("httr")
testthat::skip_if_not_installed("glue")

expect_warning(seed <- createSeed(
minValue = 100000000, maxValue = 999999999,
test_exception = "network error"
Expand Down