From wdunlap at tibco.com  Wed May 25 20:24:36 2011
From: wdunlap at tibco.com (William Dunlap)
Date: Wed, 25 May 2011 11:24:36 -0700
Subject: [Rd] External special functions (SPECIALSXP)
References: <20110525171038.GA21186@klutometis.wikitex.org><4DDD4022.5060001@gmail.com>
	<20110525180547.GA23242@klutometis.wikitex.org> 
Message-ID: <77EB52C6DD32BA4D87471DCD70C8D7000442F1FE@NA-PA-VBE03.na.tibco.com>



Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com  

> -----Original Message-----
> From: William Dunlap 
> Sent: Wednesday, May 25, 2011 11:20 AM
> To: 'Peter Danenberg'
> Cc: r-devel at r-project.org
> Subject: RE: [Rd] External special functions (SPECIALSXP)
> 
> > 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

Or, if you'd prefer a pairlist over a call to list:
  > fp <- function(...) {
  +     dotArgList <- substitute(...())
  +     dotArgList
  + }
  > fp(message=cat("foo\n"), error=stop("Oops"),
possibleProblem=warning("Hmm"))
  $message
  cat("foo\n")

  $error
  stop("Oops")
  
  $possibleProblem
  warning("Hmm")

  > class(.Last.value)
  [1] "pairlist"
I would not have thought of this syntax myself but have
seen it in other folks' code.

> Bill Dunlap
> Spotfire, TIBCO Software
> wdunlap tibco.com  
> 
> > -----Original Message-----
> > From: r-devel-bounces at r-project.org 
> > [mailto:r-devel-bounces at r-project.org] On Behalf Of Peter Danenberg
> > Sent: Wednesday, May 25, 2011 11:06 AM
> > To: Duncan Murdoch
> > Cc: r-devel at r-project.org
> > Subject: Re: [Rd] External special functions (SPECIALSXP)
> > 
> > > However, if you don't want to evaluate the arguments, just pass
> > > substitute(arg) to your function instead of arg.
> > 
> > Thanks, Duncan; the problem is, I'm trying to substitute on 
> `...' and
> > I don't think I can access `...' without inadvertently 
> evaluating it.
> > 
> > I'm trying to write a debugging function which, given any number of
> > expressions, prints the expression next to its evaluation.
> > 
> > This is trivial to do in the single arity case:
> > 
> >   debug <- function(expression) {
> >     cat(substitute(expression), expression, "\n")
> >   }
> > 
> >   a <- 2
> >   debug(a)
> > 
> >   a 2
> > 
> > but I'm not sure how to make it work with variable arity without
> > resorting to SPECIALSXP.
> > 
> > ______________________________________________
> > R-devel at r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-devel
> > 



[Rd] External special functions (SPECIALSXP)
William Dunlap