Skip to content

Commit

Permalink
Merge branch 'b-#330-new-tibble', closes #330
Browse files Browse the repository at this point in the history
- Fix copying of attributes in `new_tibble()` (#330).
  • Loading branch information
krlmlr committed Nov 8, 2017
2 parents 9f95553 + 35fb648 commit 1ae69ee
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion R/new.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ new_tibble <- function(x, ..., subclass = NULL) {
attribs <- list(...)

# reduce2() is not in the purrr compat layer
nested_attribs <- map2(names(attribs), attribs, function(name, value) list(name = value))
nested_attribs <- map2(names(attribs), attribs, function(name, value) set_names(list(value), name))
x <- reduce(
.init = x,
nested_attribs,
Expand Down
24 changes: 24 additions & 0 deletions tests/testthat/test-tbl-df.R
Original file line number Diff line number Diff line change
Expand Up @@ -295,3 +295,27 @@ test_that("is.tibble", {
test_that("is_tibble", {
expect_identical(is.tibble, is_tibble)
})

# new_tibble --------------------------------------------------------------

test_that("new_tibble", {
tbl <- new_tibble(
data.frame(a = 1),
attr1 = "val1",
attr2 = "val2",
subclass = "nt"
)

# Can't compare directly due to dplyr:::all.equal.tbl_df()
expect_identical(class(tbl), c("nt", "tbl_df", "tbl", "data.frame"))
expect_equal(
unclass(tbl),
structure(
list(a = 1),
.Names = "a",
row.names = c(NA, -1L),
attr1 = "val1",
attr2 = "val2"
)
)
})

0 comments on commit 1ae69ee

Please sign in to comment.