Just for completeness. You can use “lambda-like” (anonymous) functions in R but if you want to put them to immediate use, you need to enclose the function definition in parentheses or curly braces:
(function (x) x+1) (1)
{function (x,y) x^y} (2,3)
In the case of curve
the first argument is either expression or a function name – but if it is a function name then it is first converted to an expression. (See first few lines in the source code of curve
). So if its’ not a function name, you’ll need an expression – which may contain a “lambda” function:
curve((function (x) x^2)(x))
If you want to use a function (as opposed to its name) as the argument, you can use plot.function:
plot(function(x) x^2)