Unenclose a closure by substituting names for values found in the enclosing environment.
unenclose(f)power <- function(exp) {
function(x) x ^ exp
}
square <- power(2)
cube <- power(3)
square
#> function (x)
#> x^exp
#> <environment: 0x58b580c7fde0>
cube
#> function (x)
#> x^exp
#> <environment: 0x58b580c5a578>
unenclose(square)
#> function (x)
#> x^2
#> <environment: 0x58b580cbd830>
unenclose(cube)
#> function (x)
#> x^3
#> <environment: 0x58b580cbd830>