From tlumley at u.washington.edu  Fri Nov  6 17:42:30 2009
From: tlumley at u.washington.edu (tlumley at u.washington.edu)
Date: Fri, 6 Nov 2009 08:42:30 -0800 (PST)
Subject: [Rd] A fix that for 'bquote' that may work  (PR#14031)
In-Reply-To: <20091105035524.BB272282EF59@mail.pubhealth.ku.dk>
Message-ID: <alpine.LRH.2.01.0911060842300.305@hymn12.u.washington.edu>

On Thu, 5 Nov 2009, suharto_anggono at yahoo.com wrote:

> This is a fix for 'bquote' that may work.
>
> function (expr, where =3D parent.frame())=20
> {
>    unquote <- function(e) {
>        if (length(e) <=3D 1 || !is.language(e))=20
>            e
>        else if (e[[1]] =3D=3D as.name("."))=20
>            eval(e[[2]], where)
>        else as.call(lapply(e, unquote))
>    }
>    unquote(substitute(expr))
> }

If you want to use bquote() on function definitions a better fix is

bquote <- function (expr, where = parent.frame())
{
     unquote <- function(e) {
         if (length(e) <= 1)
             e
         else if (e[[1]] == as.name("."))
             eval(e[[2]], where)
         else if (is.pairlist(e)){
             as.pairlist(lapply(e,unquote))
         }
         else as.call(lapply(e, unquote))
     }
     unquote(substitute(expr))
}

since that now allows substitution into default arguments, eg
   default<-1
   g<-b2quote(function(x,y=.(default)) x+y )



         -thomas

Thomas Lumley			Assoc. Professor, Biostatistics
tlumley at u.washington.edu	University of Washington, Seattle



[Rd] A fix that for 'bquote' that may work (PR#14031)
tlumley at u.washington.edu