From radford at cs.toronto.edu  Sat Jul  8 22:03:20 2017
From: radford at cs.toronto.edu (Radford Neal)
Date: Sat, 8 Jul 2017 16:03:20 -0400
Subject: [Rd] bug: deparse sometimes omits parentheses for unary
	operators
In-Reply-To: <mailman.9.1499508002.52936.r-devel@r-project.org>
References: <mailman.9.1499508002.52936.r-devel@r-project.org>
Message-ID: <20170708200320.GA11757@mail.cs.toronto.edu>

> From: "Binder, Martin" <Ma.Binder at campus.lmu.de>
> To: r-devel at r-project.org
> Subject: [Rd] bug: deparse sometimes omits parentheses for unary
> 	operators
>
> Example (bad):
> > (expr = substitute(-a * 10, list(a = quote(if (TRUE) 1 else 0))))
> -if (TRUE) 1 else 0 * 10
>
> The parentheses around the "if"-construct are missing. The expected
> output (the true representation of the expression) is, in fact:
>
> -(if (TRUE) 1 else 0) * 10


It would also be OK for the result to be

  (-if (TRUE) 1 else 0) * 10

It's possible that producing this form is more natural for the deparser.

There are a number of other bugs in the deparser, many of which I
fixed in the pqR deparser when doing a major rewrite, though I missed
the one you report above.  You can see them at

    http://www.pqr-project.org/NEWS.txt

Look for BUG FIXES under VERSION RELEASED 2015-09-14.  Some are fixed
in R-3.4.0, but most remain.

   Radford Neal



[Rd] bug: deparse sometimes omits parentheses for unary operators
Radford Neal