Cross posted from stackoverflow
For a nested function such as
fun_parent <- function(var) {
fun_child <- function(x) {
x + var
}
return(fun_child)
}
How can I customize the content of the returned function fun_child based on the input var?
For example,
test <- fun_parent(var = "y")
print(test)
Desirable output:
function(x) {
x + y
}
<environment: xxxxxx>
Actual (undesirable) output:
function(x) {
x + var
}
<environment: 0x7f7f20126b70>
Any help would be greatly appreciated!