Skip to content

Commit

Permalink
fix rvar test for x[NULL] on R 4.4, for #304
Browse files Browse the repository at this point in the history
  • Loading branch information
mjskay committed Oct 30, 2023
1 parent 804efab commit b8f7da1
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
3 changes: 2 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
* Ensure `rfun()` works with primitive functions (#290) and dots arguments (#291).
* Provide implementations of `vctrs::vec_proxy_equal()`, `vctrs::vec_proxy_compare()`,
and `vctrs::vec_proxy_order()`.
* Future-proof `cbind(<rvar>)` and `rbind(<rvar>)` for R 4.4 (#304).
* Minor future-proofing of `cbind(<rvar>)`, `rbind(<rvar>)`, and `chol(<rvar>)`
for R 4.4 (#304).


# posterior 1.4.1
Expand Down
8 changes: 4 additions & 4 deletions R/rvar-slice.R
Original file line number Diff line number Diff line change
Expand Up @@ -278,15 +278,15 @@ NULL
index[seq(length(index) + 1, length(dim(.draws)) - 1)] = list(missing_arg())
}

x <- inject(
new_rvar(.draws[!!!draws_index, !!!index, drop = FALSE], .nchains = nchains(x))
)
.draws <- inject(.draws[!!!draws_index, !!!index, drop = FALSE])

if (!is_missing(draws_index[[1]])) {
# if we subsetted draws, replace draw ids with sequential ids
rownames(draws_of(x)) <- seq_len(ndraws(x))
rownames(.draws) <- seq_len(NROW(.draws))
}

x <- new_rvar(.draws, .nchains = nchains(x))

if (drop) {
x <- drop(x)
}
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-rvar-slice.R
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ test_that("indexing with [ works on a vector", {
expect_equal(x[NA_integer_], rvar_from_array(x_array[NA_integer_,, drop = FALSE]))
expect_equal(x[rep(NA_integer_,7)], rvar_from_array(x_array[rep(NA_integer_,7),, drop = FALSE]))

expect_equal(x[NULL], new_rvar(array(numeric(), dim = c(5, 0))))
expect_equal(x[NULL], rvar_from_array(x_array[NULL, , drop = FALSE]))

expect_error(x[1,1])

Expand Down

0 comments on commit b8f7da1

Please sign in to comment.