From pcd at roxygen.org  Wed May 25 21:03:22 2011
From: pcd at roxygen.org (Peter Danenberg)
Date: Wed, 25 May 2011 14:03:22 -0500
Subject: [Rd] External special functions (SPECIALSXP)
In-Reply-To: <77EB52C6DD32BA4D87471DCD70C8D7000442F1FC@NA-PA-VBE03.na.tibco.com>
References: <20110525171038.GA21186@klutometis.wikitex.org>
	<4DDD4022.5060001@gmail.com>
	<20110525180547.GA23242@klutometis.wikitex.org>
	<77EB52C6DD32BA4D87471DCD70C8D7000442F1FC@NA-PA-VBE03.na.tibco.com>
Message-ID: <20110525190322.GB24019@klutometis.wikitex.org>

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!



[Rd] External special functions (SPECIALSXP)
Peter Danenberg