diff --git a/NAMESPACE b/NAMESPACE index 3d52ad4c3..5755ecc4e 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -2,6 +2,7 @@ S3method("[[",qenv.error) S3method(within,qenv) +S3method(within,qenv.error) export(concat) export(dev_suppress) export(eval_code) diff --git a/NEWS.md b/NEWS.md index 656f83a33..580bb7398 100644 --- a/NEWS.md +++ b/NEWS.md @@ -8,6 +8,7 @@ * Exported the `qenv` class from the package. * The `@code` field in the `qenv` class now holds `character`, not `expression`. +* Added `within` support for `qenv.error` class. # teal.code 0.4.1 diff --git a/R/qenv-within.R b/R/qenv-within.R index 4302a59fb..0ebb8ec28 100644 --- a/R/qenv-within.R +++ b/R/qenv-within.R @@ -71,3 +71,11 @@ within.qenv <- function(data, expr, ...) { eval_code(object = data, code = as.expression(calls)) } + + +#' @keywords internal +#' +#' @export +within.qenv.error <- function(data, expr, ...) { + data +} diff --git a/tests/testthat/test-qenv-within.R b/tests/testthat/test-qenv-within.R index c585791a8..2002c1a5d 100644 --- a/tests/testthat/test-qenv-within.R +++ b/tests/testthat/test-qenv-within.R @@ -105,3 +105,12 @@ testthat::test_that("external values are not taken from calling frame", { # nolint end # styler: on + +testthat::test_that("within run on qenv.error returns the qenv.error as is", { + q <- qenv() + q <- within(q, i <- iris) + qe <- within(q, stop("right there")) + qee <- within(qe, m <- mtcars) + + testthat::expect_identical(qe, qee) +})