Keywords: programming
### ** Examples require(stats) formals(lm)
$formula $data $subset $weights $na.action $method [1] "qr" $model [1] TRUE $x [1] FALSE $y [1] FALSE $qr [1] TRUE $singular.ok [1] TRUE $contrasts NULL $offset $...
## If you just want the names of the arguments, use formalArgs instead. names(formals(lm))
[1] "formula" "data" "subset" "weights" "na.action" [6] "method" "model" "x" "y" "qr" [11] "singular.ok" "contrasts" "offset" "..."
methods:: formalArgs(lm) # same
[1] "formula" "data" "subset" "weights" "na.action" [6] "method" "model" "x" "y" "qr" [11] "singular.ok" "contrasts" "offset" "..."
## formals returns a pairlist. Arguments with no default have type symbol (aka name). str(formals(lm))
Dotted pair list of 14 $ formula : symbol $ data : symbol $ subset : symbol $ weights : symbol $ na.action : symbol $ method : chr "qr" $ model : logi TRUE $ x : logi FALSE $ y : logi FALSE $ qr : logi TRUE $ singular.ok: logi TRUE $ contrasts : NULL $ offset : symbol $ ... : symbol
## formals returns NULL for primitive functions. Use it in combination with ## args for this case. is.primitive(`+`)
[1] TRUE
formals(`+`)
NULL
formals(args(`+`))
$e1 $e2
## 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
function (a, b = 3) a + b <environment: 0x55ccff44c098>
f(2) # result = 5
[1] 5