Re: [Rd] A fix that for 'bquote' that may work (PR#14031)

From: <tlumley_at_u.washington.edu>
Date: Fri, 06 Nov 2009 08:42:30 -0800 (PST)


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

______________________________________________
R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Fri 06 Nov 2009 - 16:45:58 GMT

This archive was generated by hypermail 2.2.0 : Sat 07 Nov 2009 - 13:40:21 GMT