On 20/02/2024 8:03 a.m., Duncan Murdoch wrote:
I noticed the following odd behaviour today:
exprs <- expression( mean(a), mean(b), { a }, { b } )
exprs[[1]] == exprs[[2]]
#> [1] FALSE
exprs[[3]] == exprs[[4]]
#> [1] TRUE
Does it make sense to anyone that the argument passed to `mean` matters,
but the expression contained in braces doesn't?
I have done some debugging, and found the cause: for the comparison of
language objects, R deparses them to strings using C function
deparse1(), and looks at only the first line. "mean(a)" deparses as is,
but "{ a }" deparses to 3 lines
{
a
}
and the first line is the same as for "{ b }", so they compare equal.
I think it would make more sense to deparse them to one long string, and
compare those, i.e. to replace deparse1() with deparse1line() (which may
have been the intention).
Duncan Murdoch
______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel