Skip to content

Commit

Permalink
Fix #1401
Browse files Browse the repository at this point in the history
  • Loading branch information
wlandau committed Dec 17, 2024
1 parent a680e98 commit d01f86d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# targets 1.9.1.9000

* Use a more lookup-efficient data structure for `tar_runtime$file_info` (#1398).
* Fall back on vector aggregation without names (#1401, @guglicap).

# targets 1.9.1

Expand Down
17 changes: 17 additions & 0 deletions R/class_vector.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,23 @@ value_produce_slice.tar_vector <- function(value, index) { # nolint

#' @export
value_produce_aggregate.tar_vector <- function(value, objects) { # nolint
tar_vec_c(objects)
}

tar_vec_c <- function(objects) {
tryCatch(
vec_c_spec(objects),
# Covered in tests/testthat/test-class_vector.R
# but might not register in covr.
# nocov start
error = function(condition) {
do.call(vctrs::vec_c, unname(objects))
}
# nocov end
)
}

vec_c_spec <- function(objects) {
objects$.name_spec <- "{outer}_{inner}"
do.call(vctrs::vec_c, objects)
}
9 changes: 9 additions & 0 deletions tests/testthat/test-class_vector.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,12 @@ tar_test("vector$validate()", {
x <- value_init(object = "abc", iteration = "vector")
expect_silent(value_validate(x))
})

tar_test("tar_vec_c()", {
expect_equal(tar_vec_c(list(x = TRUE, y = FALSE)), c(x = TRUE, y = FALSE))
x <- structure(TRUE, class = "custom")
y <- structure(FALSE, class = "custom")
c.custom <- function(...) structure(NextMethod(), class = "custom")
out <- tar_vec_c(list(x = x, y = y))
expect_equal(as.logical(out), c(TRUE, FALSE))
})

0 comments on commit d01f86d

Please sign in to comment.