Skip to content

Commit 30d6a77

Browse files
committed
cache-> output, cache -> keep_output
1 parent 2eab262 commit 30d6a77

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

R/qenv-eval_code.R

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#' @param code (`character`, `language` or `expression`) code to evaluate.
1010
#' It is possible to preserve original formatting of the `code` by providing a `character` or an
1111
#' `expression` being a result of `parse(keep.source = TRUE)`.
12-
#' @param cache (`logical(1)`) whether to cache returned value of the code evaluation.
12+
#' @param keep_output (`logical(1)`) whether to keep the output of the code evaluation.
1313
#'
1414
#' @param ... ([`dots`]) additional arguments passed to future methods.
1515
#'
@@ -28,21 +28,21 @@
2828
#' @aliases eval_code,qenv.error-method
2929
#'
3030
#' @export
31-
setGeneric("eval_code", function(object, code, cache = FALSE, ...) standardGeneric("eval_code"))
31+
setGeneric("eval_code", function(object, code, keep_output = FALSE, ...) standardGeneric("eval_code"))
3232

33-
setMethod("eval_code", signature = c(object = "qenv"), function(object, code, cache = FALSE, ...) {
33+
setMethod("eval_code", signature = c(object = "qenv"), function(object, code, keep_output = FALSE, ...) {
3434
if (!is.language(code) && !is.character(code)) {
3535
stop("eval_code accepts code being language or character")
3636
}
3737
code <- .preprocess_code(code)
3838
# preprocess code to ensure it is a character vector
39-
.eval_code(object = object, code = code, cache = cache, ...)
39+
.eval_code(object = object, code = code, keep_output = keep_output, ...)
4040
})
4141

42-
setMethod("eval_code", signature = c(object = "qenv.error"), function(object, code, cache = FALSE, ...) object)
42+
setMethod("eval_code", signature = c(object = "qenv.error"), function(object, code, keep_output = FALSE, ...) object)
4343

4444
#' @keywords internal
45-
.eval_code <- function(object, code, cache = FALSE, ...) {
45+
.eval_code <- function(object, code, keep_output = FALSE, ...) {
4646
if (identical(code, "")) {
4747
return(object)
4848
}
@@ -64,8 +64,8 @@ setMethod("eval_code", signature = c(object = "qenv.error"), function(object, co
6464
tryCatch(
6565
{
6666
out <- eval(current_call, envir = object@.xData)
67-
if (cache && i == length(code_split)) {
68-
attr(current_code, "cache") <- out
67+
if (keep_output && i == length(code_split)) {
68+
attr(current_code, "output") <- out
6969
}
7070
if (!identical(parent.env(object@.xData), parent.env(.GlobalEnv))) {
7171
# needed to make sure that @.xData is always a sibling of .GlobalEnv

R/qenv-within.R

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#'
1010
#' @param data (`qenv`)
1111
#' @param expr (`expression`) to evaluate. Must be inline code, see `Using language objects...`
12+
#' @param keep_output (`logical(1)`) whether to keep the output of the code evaluation.
1213
#' @param ... named argument value will substitute a symbol in the `expr` matched by the name.
1314
#' For practical usage see Examples section below.
1415
#'
@@ -47,22 +48,22 @@
4748
#'
4849
#' @export
4950
#'
50-
within.qenv <- function(data, expr, ...) {
51+
within.qenv <- function(data, expr, keep_output = FALSE, ...) {
5152
expr <- as.expression(substitute(expr))
5253
extras <- list(...)
5354

5455
# Inject extra values into expressions.
5556
calls <- lapply(expr, function(x) do.call(substitute, list(x, env = extras)))
5657
do.call(
5758
eval_code,
58-
utils::modifyList(extras, list(object = data, code = as.expression(calls)))
59+
utils::modifyList(extras, list(object = data, code = as.expression(calls), keep_output = keep_output))
5960
)
6061
}
6162

6263

6364
#' @keywords internal
6465
#'
6566
#' @export
66-
within.qenv.error <- function(data, expr, ...) {
67+
within.qenv.error <- function(data, expr, keep_output = FALSE, ...) {
6768
data
6869
}

0 commit comments

Comments
 (0)