-1

I saw it "list(...)" in some R source code. But I can not execute it in R cosonle. Does anyone know what it means in R.

> list(...)
Error: '...' used in an incorrect context
zjffdu
  • 25,496
  • 45
  • 109
  • 159
  • 1
    The ellipses are a syntactic element to refer to arguments passed down from a calling function. They reference arbitrary arguments that the user of said calling function will want to supply at some point. In this case, the user will be supplying some objects to the list function, possibly named. – shayaa Aug 18 '16 at 05:29
  • Consider `foo <- function(...) list(...); foo(1:3, 5:9)` – shayaa Aug 18 '16 at 05:35

1 Answers1

3

Here is an example of how you can use the ellipses to pass arguments along.

my_list_func <- function(...) {
    list(...) # All arguments passed to function are given to 'list'
}
# Call function with various parameters. Returns a list using these params.
my_list_func(a=3, b = list(val = 1:3))
## $a
## [1] 3
## 
## $b
## $b$val
## [1] 1 2 3
steveb
  • 5,382
  • 2
  • 27
  • 36