@@ -89,6 +89,33 @@ test_that("new_rowwise_df() can add class and attributes (#5918)", {
8989 expect_equal(attr(df , " a" ), " b" )
9090})
9191
92+ test_that(" rbind() works with rowwise data frames by calling bind_rows() (r-lib/vctrs#1935)" , {
93+ x <- rowwise(tibble(a = 1 : 2 ))
94+
95+ y <- rowwise(tibble(a = 3 : 4 ))
96+ out <- rbind(x , y )
97+ expect_identical(out , rowwise(tibble(a = c(1 : 2 , 3 : 4 ))))
98+
99+ # Important that `.rows` is recreated, not copied over from `x` (r-lib/vctrs#1935)
100+ expect_identical(
101+ group_data(out ),
102+ new_tibble(list (.rows = list_of(1L , 2L , 3L , 4L )))
103+ )
104+
105+ # `bind_rows()` returns an object with the class of the first input,
106+ # which is roughly how `rbind()` also works
107+
108+ # With bare tibble
109+ y <- tibble(a = 5 : 6 )
110+ out <- rbind(x , y )
111+ expect_identical(out , rowwise(tibble(a = c(1 : 2 , 5 : 6 ))))
112+
113+ # With grouped_df
114+ y <- group_by(tibble(a = 5 : 6 ), a )
115+ out <- rbind(x , y )
116+ expect_identical(out , rowwise(tibble(a = c(1 : 2 , 5 : 6 ))))
117+ })
118+
92119test_that(" validate_rowwise_df() gives useful errors" , {
93120 df1 <- rowwise(tibble(x = 1 : 4 , g = rep(1 : 2 , each = 2 )), g )
94121 groups <- attr(df1 , " groups" )
0 commit comments