diff --git a/README.Rmd b/README.Rmd index 8426c25..079e2e3 100644 --- a/README.Rmd +++ b/README.Rmd @@ -78,7 +78,7 @@ By default the sequence depends on the class of the variable: These values can be overridden by setting the following options: -- `new_data.length_out_lgl`, which is 2 by default, for logical vectors; +- `new_data.length_out_lgl`, which is 2 by default, for logical vectors (values greater than 2 have no effect as a logical sequence is at most `c(FALSE, TRUE)`); - `new_data.length_out_dbl`, which is 30 by default, for double vectors; - `new_data.length_out_int`, which is 30 by default, for integer, Date, POSIXct and hms vectors^1; - `new_data.length_out_chr`, which is Inf by default, for character, factor and ordered vectors. diff --git a/README.md b/README.md index 5b11b25..5303e1a 100644 --- a/README.md +++ b/README.md @@ -101,7 +101,7 @@ By default the sequence depends on the class of the variable: These values can be overridden by setting the following options: -- `new_data.length_out_lgl`, which is 2 by default, for logical vectors; +- `new_data.length_out_lgl`, which is 2 by default, for logical vectors (values greater than 2 have no effect as a logical sequence is at most `c(FALSE, TRUE)`); - `new_data.length_out_dbl`, which is 30 by default, for double vectors; - `new_data.length_out_int`, which is 30 by default, for integer, Date, POSIXct and hms vectors^1; diff --git a/tests/testthat/test-new-seq.R b/tests/testthat/test-new-seq.R index cbf3972..30ca9b4 100644 --- a/tests/testthat/test-new-seq.R +++ b/tests/testthat/test-new-seq.R @@ -2261,3 +2261,26 @@ test_that("new_seq errors informatively for unsupported objects", { ) expect_error(new_seq(list(1, 2)), "not class 'list'\\.") }) + +test_that("new_seq logical .length_out greater than 2 is capped at 2", { + expect_identical(new_seq(c(TRUE, FALSE), .length_out = 3), c(FALSE, TRUE)) + expect_identical(new_seq(c(TRUE, FALSE), .length_out = Inf), c(FALSE, TRUE)) + expect_identical( + new_seq(c(TRUE, TRUE), .length_out = 3, .obs_only = TRUE), + TRUE + ) + expect_identical( + new_seq(c(TRUE, NA, FALSE), .length_out = 3, .obs_only = TRUE), + c(FALSE, TRUE) + ) +}) + +test_that("new_data.length_out_lgl option greater than 2 is capped at 2", { + withr::local_options(list(new_data.length_out_lgl = 5L)) + expect_identical(new_seq(c(TRUE, FALSE)), c(FALSE, TRUE)) + expect_identical(new_seq(c(TRUE, TRUE), .obs_only = TRUE), TRUE) + expect_identical(xnew_data(old_data, lgl)$lgl, c(FALSE, TRUE)) + + withr::local_options(list(new_data.length_out_lgl = Inf)) + expect_identical(new_seq(c(TRUE, FALSE)), c(FALSE, TRUE)) +})