How to specify arguments after points ... in R?

This probably comes down to how to pass optional parameters to R functions. Take c()for example. This definition:

c(..., recursive = FALSE)

However, if I use it as c(1:5, TRUE)it gives [1] 1 2 3 4 5 1, that is completely understandable, but also a bit strange, as I expect it to be easy to find out. I think it’s simple, and I just don’t see it all.

Cheers for the answer and don't rage. I searched Google and searched SO, but probably answered too much wrong and gave up.

EDIT: edited due to an illogical example.

+4
source share
1 answer

I was waiting for any of the first commentators to answer, but I won’t have them.

c() ..., , . , , c(). . c() ? . , ..., , , ..., .

, , TRUE ( 1) 1:5

as.numeric(TRUE)            ## numeric value of TRUE
# [1] 1
c(1:5, TRUE)                ## try no arg name, wrong result
# [1] 1 2 3 4 5 1
c(1:5, rec=TRUE)            ## try partial arg matching, wrong result
#                    rec 
#  1   2   3   4   5   1 

, recursive , .

c(1:5)
# [1] 1 2 3 4 5
c(1:5, recursive=TRUE)      ## 1:5 not recursive, same result
# [1] 1 2 3 4 5
is.recursive(c(1:5))
# [1] FALSE

(. ?is.recursive).

(x <- as.list(1:5))
# [[1]]
# [1] 1
# 
# [[2]]
# [1] 2
# 
# [[3]]
# [1] 3
# 
# [[4]]
# [1] 4
# 
# [[5]]
# [1] 5
is.recursive(x)
# [1] TRUE
c(x, recursive=TRUE)        ## correct usage on recursive object x
# [1] 1 2 3 4 5
+5

All Articles