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
setequal() function in R Language is used to check if two objects are equal. This function takes two objects like Vectors, dataframes, etc. as arguments and results in TRUE or FALSE, if the Objects are equal or not.
identical() function in R Language is used to return TRUE when two objects are equal else return FALSE.
all. equal(x, y) is a utility to compare R objects x and y testing 'near equality'. If they are different, comparison is still made to some extent, and a report of the differences is returned.
I think this is a good method. It works for many different objects:
all.equal(x,y)
[1] TRUE
Using diffobj
package:
library(diffobj)
x <- function(x) print(x + 2)
y <- function(x) print(x + 2)
diffPrint(target = x, current = y)
Wrapping it in any()
will give TRUE/FALSE:
any(diffPrint(target = x, current = y))
# FALSE
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With