Skip to content

Commit 618efbb

Browse files
committed
fix: creates special case for '='
1 parent 0c92d78 commit 618efbb

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

R/qenv-eval_code.R

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,13 @@ setMethod("eval_code", signature = c("qenv", "expression"), function(object, cod
9898
if (length(srcref)) {
9999
eval_code(object, code = paste(attr(code, "wholeSrcref"), collapse = "\n"))
100100
} else {
101-
Reduce(eval_code, init = object, x = code)
101+
Reduce(function(u, v) {
102+
if (inherits(v, "=")) {
103+
eval_code(object, paste(vapply(lang2calls(v), deparse1, collapse = "\n", character(1L)), collapse = "\n"))
104+
} else {
105+
eval_code(object = u, code = v)
106+
}
107+
}, init = object, x = code)
102108
}
103109
})
104110

tests/testthat/test-qenv_within.R

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,3 +131,21 @@ testthat::test_that("within run on qenv.error returns the qenv.error as is", {
131131

132132
testthat::expect_identical(qe, qee)
133133
})
134+
135+
testthat::describe("within run with `=`", {
136+
testthat::it("single expression", {
137+
q <- qenv()
138+
q <- within(q, {
139+
i = 1
140+
})
141+
})
142+
143+
testthat::it("multiple expressions", {
144+
q <- qenv()
145+
q <- within(q, {
146+
j <- 2
147+
i = 1
148+
})
149+
testthat::expect_equal(q$i, 1)
150+
})
151+
})

0 commit comments

Comments
 (0)