Skip to content
9 changes: 8 additions & 1 deletion R/qenv-eval_code.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
})

Expand Down
18 changes: 18 additions & 0 deletions tests/testthat/test-qenv_within.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
})