Skip to content

Commit

Permalink
Work around r-lib/vctrs#1419
Browse files Browse the repository at this point in the history
  • Loading branch information
krlmlr committed Aug 9, 2021
1 parent 357f749 commit 1382453
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion R/as_tibble.R
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ as_tibble_row <- function(x,
if (is_bare_list(x)) {
slices <- x
} else {
x <- vec_set_names(x, NULL)
x <- vectbl_set_names(x, NULL)
slices <- lapply(seq_len(vec_size(x)), vec_slice, x = x)
names(slices) <- names
}
Expand Down
2 changes: 1 addition & 1 deletion R/subsetting.R
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ NULL
x
} else {
# Drop inner names with double subscript
vec_set_names(vec_slice(x, i), NULL)
vectbl_set_names(vec_slice(x, i), NULL)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion R/tbl_df.R
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ NULL
as.data.frame.tbl_df <- function(x, row.names = NULL, optional = FALSE, ...) {
class(x) <- "data.frame"
unname <- which(!map_lgl(x, is_bare_list))
x[unname] <- map(x[unname], vec_set_names, NULL)
x[unname] <- map(x[unname], vectbl_set_names, NULL)
x
}

Expand Down
3 changes: 3 additions & 0 deletions tests/testthat/test-subsetting.R
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,9 @@ test_that("[[ drops inner names only with double subscript (#681)", {
expect_identical(df[[1, "b"]], data.frame(bb = 1))
expect_identical(df[["c"]], c)
expect_null(rownames(df[[1, "c"]]))

df <- tibble(x = new_rcrd(list(a = 1:3)))
expect_identical(df[[1, "x"]], new_rcrd(list(a = 1L)))
})

test_that("can use two-dimensional indexing with [[", {
Expand Down
5 changes: 5 additions & 0 deletions tests/testthat/test-tbl_df.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ test_that("as.data.frame() keeps inner names for lists (#837)", {
expect_identical(as.data.frame(tbl)$a, list(b = 1:3))
})

test_that("as.data.frame() keeps inner names for records", {
tbl <- tibble(x = new_rcrd(list(a = 1:3)))
expect_identical(as.data.frame(tbl)$x, new_rcrd(list(a = 1:3)))
})

test_that("names<-()", {
new_tbl <- function(...) {
data <- list(1, "b")
Expand Down

0 comments on commit 1382453

Please sign in to comment.