Skip to content

Commit

Permalink
future-proof cbind(<rvar>) and rbind(<rvar>) for R 4.4 (#304)
Browse files Browse the repository at this point in the history
  • Loading branch information
mjskay committed Oct 30, 2023
1 parent 6add3e6 commit 006d1e3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* 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).


# 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

0 comments on commit 006d1e3

Please sign in to comment.