From murdoch.duncan at gmail.com  Wed May 25 20:24:08 2011
From: murdoch.duncan at gmail.com (Duncan Murdoch)
Date: Wed, 25 May 2011 14:24:08 -0400
Subject: [Rd] External special functions (SPECIALSXP)
In-Reply-To: <20110525180547.GA23242@klutometis.wikitex.org>
References: <20110525171038.GA21186@klutometis.wikitex.org>
	<4DDD4022.5060001@gmail.com>
	<20110525180547.GA23242@klutometis.wikitex.org>
Message-ID: <4DDD4948.90800@gmail.com>

On 25/05/2011 2:05 PM, Peter Danenberg wrote:
> >  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.

I suppose you can do a clunky workaround like this:

   debug <- function(e1, e2, sentinel) {
     e1 <- if(!missing(e1)) substitute(e1)
     e2 <- if(!missing(e2)) substitute(e2)
     if (!missing(sentinel)) stop("this function only handles 2 
expressions")
     print(e1)
     print(e2)
}

(but use some finite limit that's more than 2).

Duncan Murdoch



[Rd] External special functions (SPECIALSXP)
Duncan Murdoch