ID EN
Miscellaneous

dots

R Base 3.6.2 🇮🇩 Bahasa Indonesia

… dan ..1, ..2 dll digunakan untuk merujuk pada argumen yang diturunkan dari fungsi pemanggil. Ini (dan berikut ini) hanya dapat digunakan di dalam fungsi yang memiliki ... di antara argumen formalnya. ...elt(n) adalah cara fungsional untuk mendapatkan .. dan pada dasarnya sama dengan eval(paste0("..", n)), hanya saja lebih elegan dan efisien. Perhatikan bahwa switch(n, ...) sangat dekat, berbeda dengan mengembalikan NULL tanpa terlihat alih-alih kesalahan ketika n nol atau terlalu besar. ...length() mengembalikan jumlah ekspresi dalam …. Ini sama dengan length(list(...)) tetapi tanpa mengevaluasi ekspresi di ... (yang terjadi dengan list(...)).

Syntax

R
...length()
...elt(n)

Arguments

Parameter Deskripsi
n a positive integer, not larger than the number of expressions in …, which is the same as ...length() which is the same as length(list(...)), but the latter evaluates all expressions in ….

Contoh

Example
R
# NOT RUN {
tst <- function(n, ...) ...elt(n)
tst(1, pi=pi*0:1, 2:4) ## [1] 0.000000 3.141593
tst(2, pi=pi*0:1, 2:4) ## [1] 2 3 4
try(tst(1)) # -> Error about '...' not containing an element.

tst.dl <- function(x, ...) ...length()
tst.dl(1:10)    # 0  (because the first argument is 'x')
tst.dl(4, 5)    # 1
tst.dl(4, 5, 6) # 2  namely '5, 6'
tst.dl(4, 5, 6, 7, sin(1:10), "foo"/"bar") # 5.  Note: no evaluation!
# }

See Also

… and ..1 ..2 are reserved words in R see Reserved. For more see the Introduction to R manual for usage of these syntactic elements and dotsMethods for their use in formal (S4) methods.