I have two functions, f
and g
, which have the same definition:
f <- function(x) { x + 1 }
g <- function(x) { x + 1 }
However, the identical
function considers them different:
identical(f, g)
FALSE
I presume this is because they occupy different areas in memory; identical(f, f)
gives TRUE
.
I am only interested in testing that the functions having the same definition; is there another function I can use for this?
The behaviour should be:
sameDefinition(f, f)
TRUE
sameDefinition(f, g)
TRUE
sameDefinition(f, function(x) { x + 1 })
TRUE
sameDefinition(f, function(x) { x + 3 })
FALSE
# Equivalent, but different definitions
sameDefinition(f, function(x) { x + 2 - 1 })
FALSE