# ------------ standard usage ------------
x <- 1:10
f1 <- new_function2(alist(a=), { print(a + x) }, env = environment())
f1(0)
x <- 20:23
f1(0) # result changed as x changed
# ------------ 'quasi-quosure' syntax ------------
x <- 1:10
f2 <- new_function2(alist(a=), { print(a + !!x) })
print(f2)
f2(0)
x <- 20:23
f2(0) # result doesn't change as f2 doesn't depend on x anymore
# ------------ argument settings ------------
default <- 123
# default with values pre-specified
new_function2(list(a = default)) # function (a = 123){}
# default with values unevaluated
new_function2(list(a = quote(default))) # function (a = default){}
new_function2(alist(a = default))
# missing default
new_function2(alist(a = )) # function (a){}
Run the code above in your browser using DataLab