Skip to content
Closed
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: 1 addition & 1 deletion README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
23 changes: 23 additions & 0 deletions tests/testthat/test-new-seq.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))
})
Loading