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

CRAN test fixes for rvar on R 4.4 #305

Merged
merged 3 commits into from
Oct 30, 2023
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
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +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()`.
* Minor future-proofing of `cbind(<rvar>)`, `rbind(<rvar>)`, and `chol(<rvar>)`
for R 4.4 (#304).


# posterior 1.4.1
Expand Down
14 changes: 8 additions & 6 deletions R/rvar-bind.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,18 @@ c.rvar <- function(...) {
}

#' @export
rbind.rvar <- function(...) {
# not sure why deparse.level is not passed here correctly...
deparse.level <- rlang::caller_env()$deparse.level %||% 1
rbind.rvar <- function(..., deparse.level = 1) {
# deparse.level is not correctly passed here by the default rbind
# implementation in R < 4.4, so we grab it from the calling environment
deparse.level <- rlang::caller_env()$deparse.level %||% deparse.level
bind_rvars(list(...), as.list(substitute(list(...))[-1]), deparse.level)
}

#' @export
cbind.rvar <- function(...) {
# not sure why deparse.level is not passed here correctly...
deparse.level <- rlang::caller_env()$deparse.level %||% 1
cbind.rvar <- function(..., deparse.level = 1) {
# deparse.level is not correctly passed here by the default cbind
# implementation in R < 4.4, so we grab it from the calling environment
deparse.level <- rlang::caller_env()$deparse.level %||% deparse.level
bind_rvars(list(...), as.list(substitute(list(...))[-1]), deparse.level, axis = 2)
}

Expand Down
1 change: 1 addition & 0 deletions R/rvar-math.R
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ chol.rvar <- function(x, ...) {

# drop dimension names (chol.tensor screws them around)
names(dim(result)) <- NULL
dimnames(result) <- NULL

new_rvar(result, .nchains = nchains(x))
}
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
Loading