Skip to content

feat: Support new vctrs .name_repair options: unique_quiet, universal_quiet #1625

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

Merged
merged 5 commits into from
May 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Imports:
pkgconfig,
rlang (>= 1.0.2),
utils,
vctrs (>= 0.4.2)
vctrs (>= 0.5.0)
Suggests:
bench,
bit64,
Expand Down
2 changes: 1 addition & 1 deletion R/add.R
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ rbind_at <- function(old, new, pos) {
#'
#' @export
add_column <- function(.data, ..., .before = NULL, .after = NULL,
.name_repair = c("check_unique", "unique", "universal", "minimal")) {
.name_repair = c("check_unique", "unique", "universal", "minimal", "unique_quiet", "universal_quiet")) {
if (!is.data.frame(.data)) {
deprecate_stop("2.1.1", "add_column(.data = 'must be a data frame')")
}
Expand Down
8 changes: 4 additions & 4 deletions R/as_tibble.R
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
#' df <- as_tibble(m)
as_tibble <- function(x, ...,
.rows = NULL,
.name_repair = c("check_unique", "unique", "universal", "minimal"),
.name_repair = c("check_unique", "unique", "universal", "minimal", "unique_quiet", "universal_quiet"),
rownames = pkgconfig::get_config("tibble::rownames", NULL)) {
UseMethod("as_tibble")
}
Expand All @@ -68,7 +68,7 @@ as_tibble <- function(x, ...,
#' @rdname as_tibble
as_tibble.data.frame <- function(x, validate = NULL, ...,
.rows = NULL,
.name_repair = c("check_unique", "unique", "universal", "minimal"),
.name_repair = c("check_unique", "unique", "universal", "minimal", "unique_quiet", "universal_quiet"),
rownames = pkgconfig::get_config("tibble::rownames", NULL)) {
if (!is.null(validate)) {
deprecate_stop("2.0.0", "tibble::as_tibble(validate = )", "as_tibble(.name_repair =)")
Expand Down Expand Up @@ -103,7 +103,7 @@ as_tibble.data.frame <- function(x, validate = NULL, ...,
#' @export
#' @rdname as_tibble
as_tibble.list <- function(x, validate = NULL, ..., .rows = NULL,
.name_repair = c("check_unique", "unique", "universal", "minimal")) {
.name_repair = c("check_unique", "unique", "universal", "minimal", "unique_quiet", "universal_quiet")) {
if (!is.null(validate)) {
deprecate_stop("2.0.0", "tibble::as_tibble(validate = )", "as_tibble(.name_repair =)")
}
Expand Down Expand Up @@ -279,7 +279,7 @@ as_tibble.default <- function(x, ...) {
#' as_tibble_row(list(c = "three", d = list(4:5)))
#' as_tibble_row(1:3, .name_repair = "unique")
as_tibble_row <- function(x,
.name_repair = c("check_unique", "unique", "universal", "minimal")) {
.name_repair = c("check_unique", "unique", "universal", "minimal", "unique_quiet", "universal_quiet")) {
if (!vec_is(x)) {
abort_as_tibble_row_vector(x)
}
Expand Down
6 changes: 3 additions & 3 deletions R/names.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
vectbl_names2 <- function(x,
.name_repair = c("check_unique", "unique", "universal", "minimal"),
.name_repair = c("check_unique", "unique", "universal", "minimal", "unique_quiet", "universal_quiet"),
quiet = FALSE,
call = caller_env()) {
name <- vec_names2(x, repair = "minimal", quiet = quiet)
Expand All @@ -8,7 +8,7 @@ vectbl_names2 <- function(x,

set_repaired_names <- function(x,
repair_hint,
.name_repair = c("check_unique", "unique", "universal", "minimal"),
.name_repair = c("check_unique", "unique", "universal", "minimal", "unique_quiet", "universal_quiet"),
quiet = FALSE,
call = caller_env()) {
names <- repaired_names(names2(x), repair_hint, .name_repair = .name_repair, quiet = quiet, call = call)
Expand All @@ -17,7 +17,7 @@ set_repaired_names <- function(x,

repaired_names <- function(name,
repair_hint,
.name_repair = c("check_unique", "unique", "universal", "minimal"),
.name_repair = c("check_unique", "unique", "universal", "minimal", "unique_quiet", "universal_quiet"),
quiet = FALSE,
details = NULL,
call = caller_env()) {
Expand Down
6 changes: 4 additions & 2 deletions R/tibble.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
#' * `"check_unique"`: (default value), no name repair, but check they are
#' `unique`,
#' * `"universal"`: Make the names `unique` and syntactic
#' * `"unique_quiet"`: Same as `"unique"`, but "quiet"
#' * `"universal_quiet"`: Same as `"universal"`, but "quiet"
#' * a function: apply custom name repair (e.g., `.name_repair = make.names`
#' for names in the style of base R).
#' * A purrr-style anonymous function, see [rlang::as_function()]
Expand Down Expand Up @@ -157,7 +159,7 @@
#' try(tibble(a = 2, b = !!bogus))
tibble <- function(...,
.rows = NULL,
.name_repair = c("check_unique", "unique", "universal", "minimal")) {
.name_repair = c("check_unique", "unique", "universal", "minimal", "unique_quiet", "universal_quiet")) {
xs <- quos(...)

tibble_quos(xs, .rows, .name_repair)
Expand All @@ -177,7 +179,7 @@ tibble <- function(...,
#' # Use tibble_row() to construct a one-row tibble:
#' tibble_row(a = 1, lm = lm(Height ~ Girth + Volume, data = trees))
tibble_row <- function(...,
.name_repair = c("check_unique", "unique", "universal", "minimal")) {
.name_repair = c("check_unique", "unique", "universal", "minimal", "unique_quiet", "universal_quiet")) {
xs <- enquos(...)

tibble_quos(xs, .rows = 1, .name_repair = .name_repair, single_row = TRUE)
Expand Down
5 changes: 4 additions & 1 deletion man/add_column.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 10 additions & 4 deletions man/as_tibble.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions man/tibble.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions tests/testthat/test-as_tibble.R
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,36 @@ test_that("as_tibble() implements universal names", {
)
})

test_that("as_tibble() implements unique_quiet", {
skip_if_not_installed("vctrs", "0.5.0")

expect_no_message({
invalid_df <- as_tibble(list(3, 4, 5), .name_repair = "unique_quiet")
})
expect_equal(length(invalid_df), 3)
expect_equal(nrow(invalid_df), 1)
# it is "quiet" despite `quiet` being FALSE
expect_equal(
names(invalid_df),
vec_as_names(rep("", 3), repair = "unique_quiet", quiet = FALSE)
)
})

test_that("as_tibble() implements universal_quiet", {
skip_if_not_installed("vctrs", "0.5.0")

expect_no_message({
invalid_df <- as_tibble(list(3, 4, 5), .name_repair = "universal_quiet")
})
expect_equal(length(invalid_df), 3)
expect_equal(nrow(invalid_df), 1)
# it is "quiet" despite `quiet` being FALSE
expect_equal(
names(invalid_df),
vec_as_names(rep("", 3), repair = "universal_quiet", quiet = FALSE)
)
})


test_that("as_tibble() implements custom name repair", {
expect_silent(
Expand Down
Loading