# NOT RUN {
require(stats)
formals(lm)
## If you just want the names of the arguments, use formalArgs instead.
names(formals(lm))
methods:: formalArgs(lm) # same
## formals returns a pairlist. Arguments with no default have type symbol (aka name).
str(formals(lm))
## formals returns NULL for primitive functions. Use it in combination with
## args for this case.
is.primitive(`+`)
formals(`+`)
formals(args(`+`))
## You can overwrite the formal arguments of a function (though this is
## advanced, dangerous coding).
f <- function(x) a + b
formals(f) <- alist(a = , b = 3)
f # function(a, b = 3) a + b
f(2) # result = 5
# }
Run the code above in your browser using DataLab