Skip to content

Commit f410d3e

Browse files
Creates special case for '=' processing (#253)
# Pull Request - Fixes #252 ### Changes description - Adds special case for `=` as it is not recognizes as `language` in S4 dispatch ### Note to reviewers the code with `=` call has a language type, but it tales priority somewhere on the dispatcher and tries to dispatch with this class (`->` doesn't have a problem) --------- Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 0c92d78 commit f410d3e

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

R/qenv-eval_code.R

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,14 @@ 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, "=") && identical(typeof(v), "language")) {
103+
# typeof(`=`) is language, but it doesn't dispatch on it, so we need to
104+
# explicitly pass it as first class of the object
105+
class(v) <- unique(c("language", class(v)))
106+
}
107+
eval_code(u, v)
108+
}, init = object, x = code)
102109
}
103110
})
104111

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 # nolintr: assigment. styler: off.
140+
})
141+
})
142+
143+
testthat::it("multiple '=' expressions", {
144+
q <- qenv()
145+
q <- within(q, {
146+
j = 2 # nolintr: assigment. styler: off.
147+
i = 1 # nolintr: assigment. styler: off.
148+
})
149+
testthat::expect_equal(q$i, 1)
150+
})
151+
})

0 commit comments

Comments
 (0)