[Rd] External special functions (SPECIALSXP)

Peter Danenberg pcd at roxygen.org
Wed May 25 21:03:22 CEST 2011


Quoth William Dunlap on Setting Orange, the 72nd of Discord:
> > f <- function(...) {
> +     dotArgList <- substitute(list(...))
> +     dotArgList
> + }
> > f(cat("foo\n"), stop("Oops"), warning("Hmm"))
> list(cat("foo\n"), stop("Oops"), warning("Hmm"))
> > # i.e., no argument was evaluated

Thanks, William! Something like this works perfectly:

  > debug <- function(...) {
  +   promises <- as.list(substitute(list(...)))[-1]
  +   str(structure(Map(eval, promises),
  +                 names=Map(deparse, promises)))
  + }
  >
  > a <- 2
  > debug(a, a + a)
  List of 2
   $ a    : num 2
   $ a + a: num 4
  >

For some reason, I had tried every permutation of `substitute', `list'
and `...' except that one; coming to the erroneous conclusion that I
couldn't avoid eval-ing `...'.

I may have to screw around with the evaluation environment; but,
otherwise, this is fantastic!



More information about the R-devel mailing list