Bug 17397 - Deparsed ! calls are not reparsable exactly
Summary: Deparsed ! calls are not reparsable exactly
Alias: None
Product: R
Classification: Unclassified
Component: Language (show other bugs)
Version: R 3.4.3
Hardware: All All
: P5 normal
Assignee: R-core
Depends on:
Reported: 2018-03-20 18:26 UTC by Lionel Henry
Modified: 2018-04-05 15:56 UTC (History)
1 user (show)

See Also:

Fix deparsing of ! calls (2.69 KB, application/mbox)
2018-03-20 18:26 UTC, Lionel Henry

Note You need to log in before you can comment on or make changes to this bug.
Description Lionel Henry 2018-03-20 18:26:36 UTC
Created attachment 2324 [details]
Fix deparsing of ! calls

Currently `deparse(quote(!!x))` yields "!(!x)". This is problematic
because reparsing that code gives a different parse tree. This patch
ensures that `!` calls are parsed and reparsed exactly by deparsing
quote(!!x) to "!!x".

The new behaviour is also consistent with deparsing of unary `+`, `-`
and `~` calls. The latter follow another code path because their
PPkind is PP_BINARY so the parenthesis added in the `!` case can be
explained as an oversight.

For consistency I also meant to adjust the deparser so that
`deparse(quote(??x))` yields "??x" rather than "`?`(`?`(x))" but to do
this cleanly would require adding `?` to the R_FunTab, adjust the
PPprec enum, etc. Since the deparsed code with backticks at least
reparses correctly, it didn't seem worth the trouble. Let me know if
you'd like another patch to make `?` deparsing consistent though.
Comment 1 Martin Maechler 2018-04-05 15:56:30 UTC
Agreed that this is a buglet.

Your fix (with slightly more comments in the regression checks) committed to 
R-devel.  .... may still make it into  R 3.5.0