[R] Precedence and parentheses
Duncan Murdoch
murdoch.duncan at gmail.com
Tue May 6 20:49:38 CEST 2014
On 06/05/2014 2:09 PM, Göran Broström wrote:
> A thread on r-devel ("Historical NA question") went (finally) off-topic,
> heading towards "Precedence". This triggered a question that I think is
> better put on this list:
>
> I have been more or less regularly been writing programs since the
> seventies (Fortran, later C) and I early got the habit of using
> parentheses almost everywhere, for two reasons. The first is the
> obvious, to avoid mistakes with precedences, but the second is almost as
> important: Readability.
>
> Now, I think I have seen somewhere that unnecessary parentheses in R
> functions may slow down execution time considerably. Is this really
> true, ant should I consequently get rid of my faiblesse for parentheses?
> Or are there rules for when it matters and doesn't matter?
I think "considerably" is an exaggeration, but they are kept as part of
the expression, and they do take a little bit of execution time.
The reason is to support the difference between
(x <- 1)
and
x <- 1
but they are kept even when they make no difference (other than to slow
things down).
Duncan Murdoch
More information about the R-help
mailing list