2016-05-28 33 views
0

考慮其功能的,接受任何數目的參數:確定類中的R功能的每個輸入參數

FUN <- function(...) { 
    #/some code/ 
    } 

如何確定類的輸入參數這個功能FUN

library(ggplot2) 

g <- qplot(mpg, wt, data = mtcars) 
char <- "lalala" 
DF <- data.frame(ch) 
f <- function(x) x*x 

FUN(g, char, DF, "DF", list(), f, `%in%`, NULL, TRUE, "TRUE") 

回答

2

可能這:

FUN <- function(...) { 
    elipsis <- list(...) 
    print(sapply(elipsis, class)) 
    ##/some code/ 
    } 

但是,你必須確保你逝去的明智之舉。例如:

FUN("lalala", trees, "DF", list(), function(x) x * x, `%in%`, NULL, TRUE, "TRUE") 
# [1] "character" "data.frame" "character" "list"  "function" 
# [6] "function" "NULL"  "logical" "character"