yihui / formatR

Format R Code Automatically
https://yihui.org/formatr/
256 stars 52 forks source link

Multiple assignment gets reformatted incorrectly #59

Closed bpbond closed 8 years ago

bpbond commented 8 years ago

We have an issue (see https://github.com/PecanProject/pecan/issues/1130) where formatR changed

s1 <- s2 = 0.1

to

(s1 <- s2) <- 0.1

...which is obviously syntactically different. This occurred with formatR 1.4, run with arrow=TRUE.

Thanks to @SimonGoring for spotting this.

yihui commented 8 years ago

That is not surprising to me, because <- has higher precedence than =. s1 <- s2 has to be executed before the next assignment. See ?Syntax.

In general, it is a bad idea to mix <- with =. It is fine to use either, but just not both.

bpbond commented 8 years ago

it is a bad idea

Um, yes, exactly. That's why we were running formatR on the code, to clean up that kind of thing. Well, thanks anyway.