Skip to content

Should as_tibble.tbl_df use validate? #278

@jennybc

Description

@jennybc

It is possible to mutilate a tibble and pass it through as_tibble(), even with validate = TRUE, without having the problems called out. Should validate be used even in this case?

library(tibble)

df <- tibble(
  x = 1:3,
  y = 4:6
)
names(df) <- ""
as_tibble(df)
#> # A tibble: 3 x 2
#>      ``  `NA`
#>   <int> <int>
#> 1     1     4
#> 2     2     5
#> 3     3     6
as_tibble(df, validate = TRUE)
#> # A tibble: 3 x 2
#>      ``  `NA`
#>   <int> <int>
#> 1     1     4
#> 2     2     5
#> 3     3     6
tibble:::check_tibble(df)
#> Error: Columns 1, 2 must be named

How this came up for me: I'm creating an S3 class that extends tibble. After some operations, my object should no longer bear that class, but should revert to being a plain tibble. Instead of only hand-editing the class, it seems like a good idea to also run it through as_tibble(). But then I found that as_tibble() just passes tibbles straight through, without any validation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions