Skip to content

Commit 0110716

Browse files
committed
cleanup: remove keep_output
1 parent 7e1f07a commit 0110716

File tree

5 files changed

+11
-40
lines changed

5 files changed

+11
-40
lines changed

R/qenv-eval_code.R

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
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 keep_output (`logical(1)`) whether to keep the output of the code evaluation.
13-
#'
1412
#' @param ... ([`dots`]) additional arguments passed to future methods.
1513
#'
1614
#' @return
@@ -28,21 +26,21 @@
2826
#' @aliases eval_code,qenv.error-method
2927
#'
3028
#' @export
31-
setGeneric("eval_code", function(object, code, keep_output = FALSE, ...) standardGeneric("eval_code"))
29+
setGeneric("eval_code", function(object, code, ...) standardGeneric("eval_code"))
3230

33-
setMethod("eval_code", signature = c(object = "qenv"), function(object, code, keep_output = FALSE, ...) {
31+
setMethod("eval_code", signature = c(object = "qenv"), function(object, code, ...) {
3432
if (!is.language(code) && !is.character(code)) {
3533
stop("eval_code accepts code being language or character")
3634
}
3735
code <- .preprocess_code(code)
3836
# preprocess code to ensure it is a character vector
39-
.eval_code(object = object, code = code, keep_output = keep_output, ...)
37+
.eval_code(object = object, code = code, ...)
4038
})
4139

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

4442
#' @keywords internal
45-
.eval_code <- function(object, code, keep_output = FALSE, ...) {
43+
.eval_code <- function(object, code, ...) {
4644
if (identical(code, "")) {
4745
return(object)
4846
}
@@ -63,10 +61,7 @@ setMethod("eval_code", signature = c(object = "qenv.error"), function(object, co
6361
x <- withCallingHandlers(
6462
tryCatch(
6563
{
66-
out <- eval(current_call, envir = object@.xData)
67-
if (keep_output && i == length(code_split)) {
68-
attr(current_code, "output") <- out
69-
}
64+
eval(current_call, envir = object@.xData)
7065
if (!identical(parent.env(object@.xData), parent.env(.GlobalEnv))) {
7166
# needed to make sure that @.xData is always a sibling of .GlobalEnv
7267
# could be changed when any new package is added to search path (through library or require call)

R/qenv-within.R

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
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.
1312
#' @param ... named argument value will substitute a symbol in the `expr` matched by the name.
1413
#' For practical usage see Examples section below.
1514
#'
@@ -48,22 +47,22 @@
4847
#'
4948
#' @export
5049
#'
51-
within.qenv <- function(data, expr, keep_output = FALSE, ...) {
50+
within.qenv <- function(data, expr, ...) {
5251
expr <- as.expression(substitute(expr))
5352
extras <- list(...)
5453

5554
# Inject extra values into expressions.
5655
calls <- lapply(expr, function(x) do.call(substitute, list(x, env = extras)))
5756
do.call(
5857
eval_code,
59-
utils::modifyList(extras, list(object = data, code = as.expression(calls), keep_output = keep_output))
58+
utils::modifyList(extras, list(object = data, code = as.expression(calls)))
6059
)
6160
}
6261

6362

6463
#' @keywords internal
6564
#'
6665
#' @export
67-
within.qenv.error <- function(data, expr, keep_output = FALSE, ...) {
66+
within.qenv.error <- function(data, expr, ...) {
6867
data
6968
}

man/eval_code.Rd

Lines changed: 2 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-qenv_eval_code.R

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -186,10 +186,3 @@ testthat::test_that("comments passed alone to eval_code that contain @linksto ta
186186
"x"
187187
)
188188
})
189-
190-
testthat::test_that("keep_output stores the last output of the `code` evaluation in its 'output' attribute", {
191-
q <- eval_code(qenv(), "a <- 1L;b <-2L;c<- 3L", keep_output = TRUE)
192-
testthat::expect_identical(attr(q@code[[1]], "output"), NULL)
193-
testthat::expect_identical(attr(q@code[[2]], "output"), NULL)
194-
testthat::expect_identical(attr(q@code[[3]], "output"), 3L)
195-
})

tests/testthat/test-qenv_within.R

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -154,17 +154,3 @@ testthat::test_that("Code executed with integer shorthand (1L) is the same as or
154154
q <- within(qenv(), a <- 1L)
155155
testthat::expect_identical(get_code(q), "a <- 1L")
156156
})
157-
158-
testthat::test_that("keep_output stores the last output of the `code` evaluation in its 'output' attribute", {
159-
q <- within(qenv(),
160-
{
161-
a <- 1L
162-
b <- 2L
163-
c <- 3L
164-
},
165-
keep_output = TRUE
166-
)
167-
testthat::expect_identical(attr(q@code[[1]], "output"), NULL)
168-
testthat::expect_identical(attr(q@code[[2]], "output"), NULL)
169-
testthat::expect_identical(attr(q@code[[3]], "output"), 3L)
170-
})

0 commit comments

Comments
 (0)