diff --git a/R/qenv-eval_code.R b/R/qenv-eval_code.R index b8593a33f..14af1ae78 100644 --- a/R/qenv-eval_code.R +++ b/R/qenv-eval_code.R @@ -98,7 +98,14 @@ setMethod("eval_code", signature = c("qenv", "expression"), function(object, cod if (length(srcref)) { eval_code(object, code = paste(attr(code, "wholeSrcref"), collapse = "\n")) } else { - Reduce(eval_code, init = object, x = code) + Reduce(function(u, v) { + if (inherits(v, "=") && identical(typeof(v), "language")) { + # typeof(`=`) is language, but it doesn't dispatch on it, so we need to + # explicitly pass it as first class of the object + class(v) <- unique(c("language", class(v))) + } + eval_code(u, v) + }, init = object, x = code) } }) diff --git a/tests/testthat/test-qenv_within.R b/tests/testthat/test-qenv_within.R index b4e41d0c0..9853b4608 100644 --- a/tests/testthat/test-qenv_within.R +++ b/tests/testthat/test-qenv_within.R @@ -131,3 +131,21 @@ testthat::test_that("within run on qenv.error returns the qenv.error as is", { testthat::expect_identical(qe, qee) }) + +testthat::describe("within run with `=`", { + testthat::it("single expression", { + q <- qenv() + q <- within(q, { + i = 1 # nolintr: assigment. styler: off. + }) + }) + + testthat::it("multiple '=' expressions", { + q <- qenv() + q <- within(q, { + j = 2 # nolintr: assigment. styler: off. + i = 1 # nolintr: assigment. styler: off. + }) + testthat::expect_equal(q$i, 1) + }) +})