Skip to content
Prev 389825 / 398503 Next

Environmental oddity.

On Sun, 7 Nov 2021 09:02:36 +0530
Deepayan Sarkar <deepayan.sarkar at gmail.com> wrote:

            
This seems to be caused by the deparser producing the same source text
for different expressions:

( x <- expression(`/`(`*`(a, if (b) c else d), e)) )
# expression(a * if (b) c else d/e)
( y <- expression(a * if (b) c else d/e) )
# expression(a * if (b) c else d/e)
all.equal(x, y)
# [1] TRUE

The expressions *seem* to be the same, but:

as.list(x[[1]])
# [[1]]
# `/`
# 
# [[2]]
# a * if (b) c else d
# 
# [[3]]
# e

as.list(y[[1]])
# [[1]]
# `*`
# 
# [[2]]
# a
# 
# [[3]]
# if (b) c else d/e

Perhaps it could be possible to make the deparser output extra
parentheses at the cost of slightly uglier output in cases when they
are not needed. all.equal.language uses deparse(), so it will behave
correctly when the deparse() output is fixed.

In the original example, as.list(body(d1)) and as.list(body(d2)) should
show different results, too.