How to use R's ellipsis feature when writing your own function?

前端 未结 5 533
星月不相逢
星月不相逢 2020-11-22 03:43

The R language has a nifty feature for defining functions that can take a variable number of arguments. For example, the function data.frame takes any number of

5条回答
  •  不要未来只要你来
    2020-11-22 04:31

    You gave half the answer already. Consider

    R> my_ellipsis_function <- function(...) {
    +   input_list <- as.list(substitute(list(...)))
    + }
    R> print(my_ellipsis_function(a=1:10, b=2:20))
    [[1]]
    list
    
    $a
    1:10
    
    $b
    11:20
    
    R> 
    

    So this took two arguments a and b from the call and converted it to a list. Wasn't that what you asked for?

提交回复
热议问题