diff --git a/NEWS.md b/NEWS.md index 97f94d1d..abc8cc1e 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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()` and `rbind()` for R 4.4 (#304). +* Minor future-proofing of `cbind()`, `rbind()`, and `chol()` + for R 4.4 (#304). # posterior 1.4.1 diff --git a/R/rvar-slice.R b/R/rvar-slice.R index 6f09264c..0129e37a 100755 --- a/R/rvar-slice.R +++ b/R/rvar-slice.R @@ -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) } diff --git a/tests/testthat/test-rvar-slice.R b/tests/testthat/test-rvar-slice.R index e35b09df..ccaca5a7 100755 --- a/tests/testthat/test-rvar-slice.R +++ b/tests/testthat/test-rvar-slice.R @@ -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])