Inflation R 扫帚包中的函数未按预期工作

Inflation function in R broom package not working as expected

我期待下面的代码

library(dplyr)
library(broom)

d <- data.frame(a = 1:3, b = 8:10)

d %>% inflate(x = c("apple", "orange"), y = c("car", "boat"))

给我一个 12 x 4 的数据框,如下所示:

## 1 apple boat 1 8
## 2 apple boat 2 9
## 3 apple boat 3 10
## 4 apple car 1 8
## 5 apple car 2 9
## 6 apple car 3 10
## 7 orange boat 1 8
## 8 orange boat 2 9
## 9 orange boat 3 10
## 10 orange car 1 8
## 11 orange car 2 9
## 12 orange car 3 10

但它给了我这个:

# A tibble: 4 x 2
# Groups:   x, y [4]
       x     y
   <chr> <chr>
1  apple  boat
2  apple   car
3 orange  boat
4 orange   car

似乎忽略了d。怎么回事?

尝试 tidyr::crossing:

library(tidyr)

d <- data.frame(a = 1:3, 
                b = 8:10)

d %>% crossing(x = c("apple", "orange"), 
               y = c("car", "boat"))
#>    a  b      x    y
#> 1  1  8  apple boat
#> 2  1  8  apple  car
#> 3  1  8 orange boat
#> 4  1  8 orange  car
#> 5  2  9  apple boat
#> 6  2  9  apple  car
#> 7  2  9 orange boat
#> 8  2  9 orange  car
#> 9  3 10  apple boat
#> 10 3 10  apple  car
#> 11 3 10 orange boat
#> 12 3 10 orange  car