ID EN
Control Flow

formals

R Base 3.6.2 🇮🇩 Bahasa Indonesia

Dapatkan atau atur argumen formal suatu fungsi.

Syntax

R
formals(fun = sys.function(sys.parent()), envir = parent.frame())
formals(fun, envir = environment(fun)) <- value

Arguments

Parameter Deskripsi
fun a function, or see ‘Details’.
envir environment in which the function should be defined (or found via get() in the first case and when fun a character string).
value a list (or pairlist) of R expressions.

Return Value

formals mengembalikan daftar argumen formal dari fungsi yang ditentukan, sebagai daftar pasangan, atau NULL untuk non-fungsi atau primitif. Formulir pengganti menetapkan formal suatu fungsi ke daftar/daftar pasangan di sisi kanan, dan (berpotensi) mengatur ulang lingkungan fungsi.

Details

Untuk bentuk pertama, fun juga bisa berupa string karakter yang memberi nama fungsi yang akan dimanipulasi, yang dicari di envir, secara default dari frame induk. Jika tidak ditentukan, pemanggilan fungsi formal digunakan. Hanya penutupan yang memiliki fungsi formal, bukan fungsi primitif.

Contoh

Example
R
# 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
# }

See Also

formalArgs (from methods) a shortcut for names(formals(.)). args for a human-readable version alist body function.