[Rd] all.equal applied to function closures

Kevin Van Horn v@nhorn @end|ng |rom @dobe@com
Mon Nov 30 19:05:52 CET 2020

Consider the following code:

    f <- function(x)function(y){x+y}
    all.equal(f(5), f(0))

This returns TRUE, when it should return FALSE; I think it’s hard to make the case that f(5) and f(0) are “approximately equal” in any meaningful sense. Digging into the code for all.equal(), I see that all.equal(f(5), f(0)) results in a call to all.equal.language(f(5), f(0)), which only compares the function texts for equality.

If it is decided to leave this behavior as-is, then at least it should be documented. Currently I cannot find any documentation for all.equal applied to functions.

	[[alternative HTML version deleted]]

More information about the R-devel mailing list