Skip to content

Commit 95f9529

Browse files
paleolimbotthomasp85
authored andcommitted
Tests to make sure facet_wrap() and facet_grid() can facet by date (#3330)
1 parent ff268a5 commit 95f9529

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

tests/testthat/test-facet-map.r

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,38 @@ test_that("wrap: missing facet columns are duplicated", {
5959
expect_equal(loc_c$PANEL, factor(1:4))
6060
})
6161

62+
test_that("wrap and grid can facet by a date variable", {
63+
date_df <- data_frame(date_var = as.Date(c("1971-12-11", "1987-01-13", "2000-01-01")))
64+
65+
wrap <- facet_wrap(~date_var)
66+
loc_wrap <- panel_map_one(wrap, date_df)
67+
expect_equal(loc_wrap$PANEL, factor(1:3))
68+
69+
grid_col <- facet_grid(~date_var)
70+
loc_grid_col <- panel_map_one(grid_col, date_df)
71+
expect_equal(loc_grid_col$PANEL, factor(1:3))
72+
73+
grid_row <- facet_grid(date_var ~ .)
74+
loc_grid_row <- panel_map_one(grid_row, date_df)
75+
expect_equal(loc_grid_row$PANEL, factor(1:3))
76+
})
77+
78+
test_that("wrap and grid can facet by a POSIXct variable", {
79+
date_df <- data_frame(date_var = as.POSIXct(c("1971-12-11", "1987-01-13", "2000-01-01")))
80+
81+
wrap <- facet_wrap(~date_var)
82+
loc_wrap <- panel_map_one(wrap, date_df)
83+
expect_equal(loc_wrap$PANEL, factor(1:3))
84+
85+
grid_col <- facet_grid(~date_var)
86+
loc_grid_col <- panel_map_one(grid_col, date_df)
87+
expect_equal(loc_grid_col$PANEL, factor(1:3))
88+
89+
grid_row <- facet_grid(date_var ~ .)
90+
loc_grid_row <- panel_map_one(grid_row, date_df)
91+
expect_equal(loc_grid_row$PANEL, factor(1:3))
92+
})
93+
6294
# Missing behaviour ----------------------------------------------------------
6395

6496
a3 <- data_frame(

0 commit comments

Comments
 (0)