From murdoch.duncan at gmail.com  Sat Feb 16 16:18:58 2013
From: murdoch.duncan at gmail.com (Duncan Murdoch)
Date: Sat, 16 Feb 2013 10:18:58 -0500
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: <511FA362.9060305@gmail.com>

On 13-02-15 10:45 AM, Hadley Wickham 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)

This is a little tricky for the deparser.  It sees a call to a function 
which was determined by an expression.  Sometimes you want parens, 
sometimes you don't.  For example, if getfun(y) returns a function, it's 
clearer to display a call as getfun(y)(x) than (getfun(y))(x).

I'll see if I can work out which kinds of expressions need to be 
parenthesized and implement it in the deparser.

Duncan



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