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

Duncan Murdoch murdoch.duncan at gmail.com
Sat Feb 16 17:39:39 CET 2013


On 13-02-16 10:19 AM, Hadley Wickham wrote:
> On Sat, Feb 16, 2013 at 12:24 AM, Bert Gunter <gunter.berton at gene.com> wrote:
>> 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
>
> Thomas Lumley sent me a similar suggestion off-list; but I'm not
> complaining about how it works; my example executed fine. I'm
> complaining that the rendering of the call object is misleading.

Even with the braces it's misleading, in that

y <- function (x)
{
     x + 1
}(x)

is evaluated to define y to be a function with body

{
     x + 1
}(x)

which is syntactically valid, but not the same as the thing being deparsed.

Duncan Murdoch



More information about the R-devel mailing list