|
1 | 1 | context("Performance related alternatives")
|
2 | 2 |
|
| 3 | +# ******************** |
| 4 | +# modify_list() |
| 5 | + |
3 | 6 | testlist <- list(
|
4 | 7 | a = 5.5,
|
5 | 8 | b = "x",
|
@@ -32,3 +35,35 @@ test_that("modify_list erases null elements", {
|
32 | 35 | expect_null(res$c)
|
33 | 36 | expect_named(res, c('a', 'b', 'd'))
|
34 | 37 | })
|
| 38 | + |
| 39 | + |
| 40 | +# ******************** |
| 41 | +# new_data_frame() |
| 42 | + |
| 43 | +test_that("new_data_frame handles zero-length inputs", { |
| 44 | + # zero-length input creates zero-length data frame |
| 45 | + d <- new_data_frame(list(x = numeric(0), y = numeric(0))) |
| 46 | + expect_equal(nrow(d), 0L) |
| 47 | + |
| 48 | + # constants are ignored in the context of zero-length input |
| 49 | + d <- new_data_frame(list(x = numeric(0), y = numeric(0), z = 1)) |
| 50 | + expect_equal(nrow(d), 0L) |
| 51 | + |
| 52 | + # vectors of length > 1 don't mix with zero-length input |
| 53 | + expect_error( |
| 54 | + new_data_frame(list(x = numeric(0), y = numeric(0), z = 1, a = c(1, 2))), |
| 55 | + "Elements must equal the number of rows or 1" |
| 56 | + ) |
| 57 | + |
| 58 | + # explicit recycling doesn't work with zero-length input |
| 59 | + expect_error( |
| 60 | + new_data_frame(list(x = numeric(0), z = 1), n = 5), |
| 61 | + "Elements must equal the number of rows or 1" |
| 62 | + ) |
| 63 | + # but it works without |
| 64 | + d <- new_data_frame(list(x = 1, y = "a"), n = 5) |
| 65 | + expect_equal(nrow(d), 5L) |
| 66 | + expect_identical(d$x, rep(1, 5L)) |
| 67 | + expect_identical(d$y, rep("a", 5L)) |
| 68 | + |
| 69 | +}) |
0 commit comments