From gunter.berton at gene.com  Sat Feb 16 07:24:19 2013
From: gunter.berton at gene.com (Bert Gunter)
Date: Fri, 15 Feb 2013 22:24:19 -0800
Subject: [Rd] Printing of anonymous functions in calls is sub-optimal
In-Reply-To: <CABdHhvEgK1g4gYhmovu_EbvSN185g9LnLAacC5ojWup3_aG07w@mail.gmail.com>
References: <CABdHhvEgK1g4gYhmovu_EbvSN185g9LnLAacC5ojWup3_aG07w@mail.gmail.com>
Message-ID: <CACk-te153qhWuzN4MwcozknhM38kNVv6MtJKKg-r1eVx9ODs0w@mail.gmail.com>

As there has been no response to this ...

Why not simply:

> g <- substitute(f(x),list(f=function(x){x+1})) ## with curly braces
> g
function (x)
{
    x + 1
}(x)
> x <- 2
> eval(g)
[1] 3


Cheers,
Bert

On Fri, Feb 15, 2013 at 7:45 AM, Hadley Wickham <h.wickham at gmail.com> wrote:
> e.g.
>
> substitute(f(x), list(f = function(x) x + 1))
> # function (x)
> # x + 1(x)
>
> An extra pair of parentheses would really help:
>
> (function(x)
> x + 1)(x)
>
> (Better indenting etc would be nice, but not necessary for correct
> understand of the code)
>
> Hadley
>
> --
> Chief Scientist, RStudio
> http://had.co.nz/
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel



-- 

Bert Gunter
Genentech Nonclinical Biostatistics

Internal Contact Info:
Phone: 467-7374
Website:
http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm



[Rd] Printing of anonymous functions in calls is sub-optimal
Bert Gunter