确定R函数中每个输入参数的类

时间:2016-05-28 13:22:03

标签: r function

考虑使用一个接受任意数量参数的函数:

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

如何确定此函数的{strong>类输入参数 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")

1 个答案:

答案 0 :(得分: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"