From h.wickham at gmail.com  Sat Feb 16 16:22:28 2013
From: h.wickham at gmail.com (Hadley Wickham)
Date: Sat, 16 Feb 2013 09:22:28 -0600
Subject: [Rd] Printing of anonymous functions in calls is sub-optimal
In-Reply-To: <511FA362.9060305@gmail.com>
References: <CABdHhvEgK1g4gYhmovu_EbvSN185g9LnLAacC5ojWup3_aG07w@mail.gmail.com>
	<511FA362.9060305@gmail.com>
Message-ID: <CABdHhvGsqp76OZYLm12R9AvrekY5KnL3tOwPHpSnc0c2=DPyvQ@mail.gmail.com>

> 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.

I suspect it's only when you have a function in the quoted call, not a symbol:

# Don't add parens
q1 <- quote(g(f)(x))
is.symbol(q1[[1]])

# Add parents
q2 <- substitute(f(x), list(f = function(x) {x + 1}))
is.function(q2[[1]])

Thanks for thinking about it!

Hadley

-- 
Chief Scientist, RStudio
http://had.co.nz/



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