Skip to content
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

Fix bug in vec_recycle_common() #1701

Merged
merged 2 commits into from
Apr 17, 2024
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
6 changes: 5 additions & 1 deletion R/standalone-vctrs.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
# of data frames without having to depend on tibble or vctrs. The
# embedded type system is minimal and not extensible.

# 2024-04-17:
# * `vec_recycle_common()` throws intended error when `size = 1` but input
# is larger.

# 2021-08-27:
# * `vec_slice()` now preserves attributes of data frames and vectors.
# * `vec_ptype2()` detects unspecified columns of data frames.
Expand Down Expand Up @@ -118,7 +122,7 @@ vec_recycle_common <- function(xs, size = NULL) {
} else if (ns == 1) {
if (is.null(size)) {
size <- n
} else if (ns != size) {
} else if (n != size) {
stop("Inputs can't be recycled to `size`.", call. = FALSE)
}
} else {
Expand Down
13 changes: 13 additions & 0 deletions tests/testthat/test-standalone-vctrs.R
Original file line number Diff line number Diff line change
Expand Up @@ -452,3 +452,16 @@ test_that("ptype is finalised", {
out <- vec_cast_common(list(out, x))[[1]]
expect_identical(out$x, NA)
})

test_that("vec_recycle_common() throws appropriate errors", {

expect_error(
vec_recycle_common(list(a = 1:2), size = 1),
"Inputs can't be recycled to `size`."
)
expect_error(
vec_recycle_common(list(a = 1:2, b = 1:3)),
"Inputs can't be recycled to a common size."
)

})
Loading