# return first argument evaluated at second argument squared.
sq <- function(f, x) f(x^2)
# call sq using different forms for function
sq(function(x) exp(x)/x, pi)
f <- function(x) exp(x)/x
sq("f", pi)
sq(~ exp(x)/x, pi)
sq(x ~ exp(x)/x, pi)
Run the code above in your browser using DataLab