Skip to content
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
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

* `eval_code` uses `evaluate::evaluate` and stores returned outputs in the code's attribute.
* Refactor `eval_code` method signature to allow for more flexibility when extending the `eval_code`/`within` functions.
* `get_var(qenv, ...)` and `join(qenv, ...)` were hard deprecated.

# teal.code 0.6.1

Expand Down
3 changes: 2 additions & 1 deletion R/qenv-get_outputs.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#' Get outputs
#'
#' @description
#' @description `r lifecycle::badge("experimental")`
#'
#' `eval_code` evaluates code silently so plots and prints don't show up in the console or graphic devices.
#' If one wants to use an output outside of the `qenv` (e.g. use a graph in `renderPlot`) then use `get_outputs`.
#' @param object (`qenv`)
Expand Down
41 changes: 4 additions & 37 deletions R/qenv-get_var.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,45 +5,12 @@
#' Instead of [get_var()] use native \R operators/functions:
#' `x[[name]]`, `x$name` or [get()]:
#'
#' Retrieve variables from the `qenv` environment.
#'
#' @param object,x (`qenv`)
#' @param var,i (`character(1)`) variable name.
#'
#' @return The value of required variable (`var`) within `qenv` object.
#'
#' @examples
#' q <- qenv()
#' q1 <- eval_code(q, code = quote(a <- 1))
#' q2 <- eval_code(q1, code = "b <- a")
#' get_var(q2, "b")
#'
#' @aliases get_var,qenv,character-method
#' @aliases get_var,qenv.error,ANY-method
#' @param ... function is deprecated.
#' @param x (`qenv`)
#' @param i (`character(1)`) variable name.
#'
#' @export
setGeneric("get_var", function(object, var) {
dev_suppress(object)
standardGeneric("get_var")
})

setMethod("get_var", signature = c("qenv", "character"), function(object, var) {
lifecycle::deprecate_soft("0.6.0", "get_var()", "base::get()")
tryCatch(
get(var, envir = object@.xData, inherits = FALSE),
error = function(e) {
message(conditionMessage(e))
NULL
}
)
})

setMethod("get_var", signature = c("qenv.error", "ANY"), function(object, var) {
stop(errorCondition(
list(message = conditionMessage(object)),
class = c("validation", "try-error", "simpleError")
))
})
get_var <- function(...) lifecycle::deprecate_stop("0.6.0", "get_var()", "base::get()")
Copy link
Contributor

@gogonzo gogonzo Aug 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does It suppose to be when = "0.6.2"?


#' @rdname get_var
#' @export
Expand Down
147 changes: 4 additions & 143 deletions R/qenv-join.R
Original file line number Diff line number Diff line change
@@ -1,152 +1,13 @@
#' Join `qenv` objects
#'
#' @description
#' Checks and merges two `qenv` objects into one `qenv` object.
#' `r lifecycle::badge("deprecated")`
#' Instead of [join()] use [c()].
#'
#' The `join()` function is superseded by the `c()` function.
#'
#' @details
#' Any common code at the start of the `qenvs` is only placed once at the start of the joined `qenv`.
#' This allows consistent behavior when joining `qenvs` which share a common ancestor.
#' See below for an example.
#'
#' There are some situations where `join()` cannot be properly performed, such as these three scenarios:
#' 1. Both `qenv` objects contain an object of the same name but are not identical.
#'
#' Example:
#'
#' ```r
#' x <- eval_code(qenv(), expression(mtcars1 <- mtcars))
#' y <- eval_code(qenv(), expression(mtcars1 <- mtcars['wt']))
#'
#' z <- c(x, y)
#' # Error message will occur
#' ```
#' In this example, `mtcars1` object exists in both `x` and `y` objects but the content are not identical.
#' `mtcars1` in the `x qenv` object has more columns than `mtcars1` in the `y qenv` object (only has one column).
#'
#' 2. `join()` will look for identical code elements in both `qenv` objects.
#' The index position of these code elements must be the same to determine the evaluation order.
#' Otherwise, `join()` will throw an error message.
#'
#' Example:
#' ```r
#' common_q <- eval_code(qenv(), expression(v <- 1))
#' x <- eval_code(
#' common_q,
#' "x <- v"
#' )
#' y <- eval_code(
#' common_q,
#' "y <- v"
#' )
#' z <- eval_code(
#' y,
#' "z <- v"
#' )
#' q <- c(x, y)
#' join_q <- c(q, z)
#' # Error message will occur
#'
#' # Check the order of evaluation based on the id slot
#' ```
#' The error occurs because the index position of common code elements in the two objects is not the same.
#'
#' 3. The usage of temporary variable in the code expression could cause `join()` to fail.
#'
#' Example:
#' ```r
#' common_q <- qenv()
#' x <- eval_code(
#' common_q,
#' "x <- numeric(0)
#' for (i in 1:2) {
#' x <- c(x, i)
#' }"
#' )
#' y <- eval_code(
#' common_q,
#' "y <- numeric(0)
#' for (i in 1:3) {
#' y <- c(y, i)
#' }"
#' )
#' q <- join(x,y)
#' # Error message will occur
#'
#' # Check the value of temporary variable i in both objects
#' x$i # Output: 2
#' y$i # Output: 3
#' ```
#' `c()` fails to provide a proper result because of the temporary variable `i` exists
#' in both objects but has different value.
#' To fix this, we can set `i <- NULL` in the code expression for both objects.
#' ```r
#' common_q <- qenv()
#' x <- eval_code(
#' common_q,
#' "x <- numeric(0)
#' for (i in 1:2) {
#' x <- c(x, i)
#' }
#' # dummy i variable to fix it
#' i <- NULL"
#' )
#' y <- eval_code(
#' common_q,
#' "y <- numeric(0)
#' for (i in 1:3) {
#' y <- c(y, i)
#' }
#' # dummy i variable to fix it
#' i <- NULL"
#' )
#' q <- c(x,y)
#' ```
#'
#' @param x (`qenv`)
#' @param y (`qenv`)
#'
#' @return `qenv` object.
#'
#' @examples
#' q <- qenv()
#' q1 <- eval_code(q, expression(iris1 <- iris, mtcars1 <- mtcars))
#' q2 <- q1
#' q1 <- eval_code(q1, "iris2 <- iris")
#' q2 <- eval_code(q2, "mtcars2 <- mtcars")
#' qq <- join(q1, q2)
#' cat(get_code(qq))
#'
#' common_q <- eval_code(q, quote(x <- 1))
#' y_q <- eval_code(common_q, quote(y <- x * 2))
#' z_q <- eval_code(common_q, quote(z <- x * 3))
#' join_q <- join(y_q, z_q)
#' # get_code only has "x <- 1" occurring once
#' cat(get_code(join_q))
#'
#' @include qenv-errors.R
#' @param ... function is deprecated.
#'
#' @name join
#' @rdname join
#' @aliases join,qenv,qenv-method
#' @aliases join,qenv,qenv.error-method
#' @aliases join,qenv.error,ANY-method
#'
#' @export
setGeneric("join", function(x, y) standardGeneric("join"))

setMethod("join", signature = c("qenv", "qenv"), function(x, y) {
lifecycle::deprecate_soft("0.6.0", "join()", "c()")
c(x, y)
})

setMethod("join", signature = c("qenv", "qenv.error"), function(x, y) {
lifecycle::deprecate_soft("0.6.0", "join()", "c()")
y
})

setMethod("join", signature = c("qenv.error", "ANY"), function(x, y) {
lifecycle::deprecate_soft("0.6.0", "join()", "c()")
x
})
join <- function(...) lifecycle::deprecate_stop("0.6.0", "join()", "c()")
2 changes: 2 additions & 0 deletions man/get_outputs.Rd

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

22 changes: 5 additions & 17 deletions man/get_var.Rd

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

Loading
Loading