Kevin Burnham Kevin Burnham - 2 months ago 17
R Question

Testing equality of two functions in R

Is there a way to determine if the text of two different functions is identical?

x <- function(x) print(x + 2)
y <- function(x) print(x + 2)
identical(x, y)
[1] FALSE
identical(mget("x"), mget("y"))
[1] FALSE
identical(unname(mget("x")), unname(mget("y")))
[1] FALSE

Answer

I think this is a good method. It works for many different objects:

all.equal(x,y)
[1] TRUE
Comments