New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should as_tibble.tbl_df use `validate`? #278

Closed
jennybc opened this Issue Jul 19, 2017 · 1 comment

Comments

Projects
None yet
2 participants
@jennybc
Member

jennybc commented Jul 19, 2017

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.

@krlmlr krlmlr closed this in bdf23e6 Jul 27, 2017

@krlmlr

This comment has been minimized.

Member

krlmlr commented Jul 27, 2017

Thanks for bringing this up.

krlmlr added a commit that referenced this issue Jul 28, 2017

Merge tag 'v1.3.3.9001'
- Escape factor levels when printing (#277).
- Adding columns to zero-row data frames now also works when mixing
lengths 1 and 0 in the new columns (#167).
- Non-syntactic names are now also escaped in `glimpse()` (#280).
- The `validate` argument is now also supported in `as_tibble.tbl_df()`,
with default to `FALSE` (#278).

krlmlr added a commit that referenced this issue Aug 22, 2017

Merge tag 'v1.3.4'
Bug fixes
---------

- Values of length 1 in a `tibble()` call are recycled prior to evaluating subsequent arguments, improving consistency with `mutate()` (#213).
- Recycling of values of length 1 in a `tibble()` call maintains their class (#284).
- `add_row()` now always preserves the column data types of the input data frame the same way as `rbind()` does (#296).
- `lst()` now again handles duplicate names, the value defined last is used in case of a clash.
- Adding columns to zero-row data frames now also works when mixing lengths 1 and 0 in the new columns (#167).
- The `validate` argument is now also supported in `as_tibble.tbl_df()`, with default to `FALSE` (#278).  It must be passed as named argument, as in `as_tibble(validate = TRUE)`.

Formatting
----------

- `format_v()` now always surrounds lists with `[]` brackets, even if their length is one. This affects `glimpse()` output for list columns (#106).
- Factor levels are escaped when printing (#277).
- Non-syntactic names are now also escaped in `glimpse()` (#280).
- `tibble()` gives a consistent error message in the case of duplicate column names (#291).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment