Hashes a function, but considering the formals and body, thus the resulting has is influenced by changes to signature and implementation.

# S3 method for class '`function`'
hash(value)

Arguments

value

value to hash

Value

hashed value as a string

Examples

my.function <- function (x, y) x+y

# a list of values to hash
values <- list(
  "Hello world!",
  101,
  3.142,
  TRUE,
  my.function,
  (function (x, y) x+y),
  functionCall(my.function, call("my.function", 10, 10)),
  list(a=1, b=2, c="hello")
)

# hash the values in the list
(hashes <- lapply(values, hash))
#> [[1]]
#> [1] "16b7be13540e73459f61994a22b8f213"
#> 
#> [[2]]
#> [1] "16e8b34f96a712da6a2c777162d0d032"
#> 
#> [[3]]
#> [1] "a1f25f79aa7db7dd9a9568405ff5cbc5"
#> 
#> [[4]]
#> [1] "bb73ad91bcb7e948250d465016f7bea8"
#> 
#> [[5]]
#> [1] "8b331ebc7ab9fd41f9d8f361403b7161"
#> 
#> [[6]]
#> [1] "8b331ebc7ab9fd41f9d8f361403b7161"
#> 
#> [[7]]
#> [1] "08c6f757f4217e477295f6a38cc092f5"
#> 
#> [[8]]
#> [1] "fac8a04274af9ddca322dffa790ae3cc"
#> 

# Note that functions with the same body will have the same hash
hashes[[5]] == hashes[[6]]
#> [1] TRUE