Skip to content

Commit

Permalink
exclude names when repopulating attrs. fixes #16
Browse files Browse the repository at this point in the history
  • Loading branch information
khusmann committed Oct 12, 2024
1 parent fb842a9 commit 24be795
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion R/interlaced.R
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ new_interlaced <- function(value_channel, na_channel, ...) {
)

for (i in names(attributes(value_channel))) {
if (i != "class") {
if (i != "class" && i != "names") {
if (!is.null(attr(v, i))) {
cli_abort("attribute {i} in value vector conflicts with interlaced")
}
Expand Down
7 changes: 7 additions & 0 deletions tests/testthat/test-interlaced.R
Original file line number Diff line number Diff line change
Expand Up @@ -222,3 +222,10 @@ test_that("model.frame drops na_channel", {
expect_equal(value_channel(mod$b), c(1, 3))
expect_equal(na_channel(mod$b), unspecified(2))
})

test_that("vector names are preserved", {
foo <- interlaced(c(a=1, b=2, c=-99), c(-99))

expect_equal(names(foo), c("a", "b", "c"))
expect_equal(value_channel(foo), c(a=1, b=2, c=NA))
})

0 comments on commit 24be795

Please sign in to comment.