Skip to content
Prev 300983 / 398503 Next

turning R expressions into functions?

list(...) evaluates the things in ...
E.g.,
   > f0 <- function(x, ...) list(...)
   > f0(1, warning("Hmm"), stop("Oops"), cat("some output\n"))[[2]]
   Error in f0(1, warning("Hmm"), stop("Oops"), cat("some output\n")) : Oops
   In addition: Warning message:
   In f0(1, warning("Hmm"), stop("Oops"), cat("some output\n")) : Hmm

You can use the odd idiom substitute(...()) to get the unevaluated ... arguments:
   > f1 <- function(x, ...) substitute(...())
   > f1(1, warning("Hmm"), stop("Oops"), cat("some output\n"))
   [[1]]
   warning("Hmm")

   [[2]]
   stop("Oops")

   [[3]]
   cat("some output\n")


Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com