Skip to content

Commit

Permalink
handle reactive expressions in upgrade/downgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
Aleksander Chlebowski committed Nov 20, 2023
1 parent fc8c690 commit 1146f0d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
13 changes: 12 additions & 1 deletion R/tdata.R
Original file line number Diff line number Diff line change
Expand Up @@ -175,14 +175,21 @@ get_metadata.default <- function(data, dataname) {
#'
#' Note the `metadata` attribute is discarded.
#'
#' @param `x` data object, either `tdata` or `teal_data`
#' In apps and modules data objects passed to upgrade/downgrade may be reactive expressions.
#' For convenience, these functions accept reactive expressions2 and run on their values.
#'
#' @param `x` data object, either `tdata` or `teal_data`; reactive expressions are handled, see `Details`
#'
#' @return Object of class `tdata` for `.tdata_upgrade` and `tdata` for `.tdata_downgrade`.
#'
#' @keywords internal
#' @rdname tdata_deprecation
#'
.tdata_upgrade <- function(x) {
if (is.reactive(x)) {
x <- x()
}

checkmate::assert_multi_class(x, c("tdata", "teal_data"))

if (inherits(x, "qenv")) {
Expand All @@ -200,6 +207,10 @@ get_metadata.default <- function(data, dataname) {
#' @rdname tdata_deprecation
#'
.tdata_downgrade <- function(x) {
if (is.reactive(x)) {
x <- x()
}

checkmate::assert_multi_class(x, c("tdata", "teal_data"))

if (!inherits(x, "qenv")) {
Expand Down
5 changes: 4 additions & 1 deletion man/tdata_deprecation.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1146f0d

Please sign in to comment.