Determine class of every input argument in R function -
consider having function, accepts number of arguments:
fun <- function(...) { #/some code/ }
how determine classes of input arguments function 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")
possibly this:
fun <- function(...) { elipsis <- list(...) print(sapply(elipsis, class)) ##/some code/ }
however, must make sure passing in sensible thing. example:
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"
Comments
Post a Comment