-
Notifications
You must be signed in to change notification settings - Fork 135
Closed
Labels
reprexneeds a minimal reproducible exampleneeds a minimal reproducible example
Milestone
Description
Generally, tibble() drops NULL input columns
library(tibble)
tibble(x = 1:3, y = NULL)
#> # A tibble: 3 x 1
#> x
#> <int>
#> 1 1
#> 2 2
#> 3 3But if the tibble() call is wrapped up in a function, then the internal usage of quo_is_null() doesn't see the input as a NULL value.
library(tibble)
make_tibble <- function(x, y) {
tibble(x = x, y = y)
}
xx <- make_tibble(1:3, NULL)
xx
#> Error: Internal error in `df_slice()`: Columns must match the data frame size.
str(xx)
#> tibble [3 × 2] (S3: tbl_df/tbl/data.frame)
#> $ x: int [1:3] 1 2 3
#> $ y: NULLI'm fairly certain an easy fix for this is to switch from quos() to enquos() in tibble(), that should be more appropriate anyways as enquos() is for capturing arguments:
Line 149 in 6fb9a90
| xs <- quos(...) |
And here in tibble_row(), might need to look for more usage of it:
Line 171 in 6fb9a90
| xs <- quos(...) |
Here is an example of quos vs enquos:
wrap_quos <- function(x, y) {
rlang::quos(x = x, y = y)
}
wrap_enquos <- function(x, y) {
rlang::enquos(x = x, y = y)
}
wrap_quos(1:3, NULL)
#> <list_of<quosure>>
#>
#> $x
#> <quosure>
#> expr: ^x
#> env: 0x7ff0fff0ba70
#>
#> $y
#> <quosure>
#> expr: ^y
#> env: 0x7ff0fff0ba70
wrap_enquos(1:3, NULL)
#> <list_of<quosure>>
#>
#> $x
#> <quosure>
#> expr: ^1:3
#> env: global
#>
#> $y
#> <quosure>
#> expr: ^NULL
#> env: emptyMetadata
Metadata
Assignees
Labels
reprexneeds a minimal reproducible exampleneeds a minimal reproducible example