13

is there a solution to use more than one equals signs in a expression (which are not within brackets)? I'm currently doing it with " = ". But thats not so nice, since == and " = " look different on the plot.

Minimal sample:

plot(0:5,0:5, type="n")
saleprice <- 35
revenue <- 98000
text(1, 2, 
     bquote(paste(R(x[G]) == .(saleprice)%.%x[G], " = ", .(revenue))))

See the following image for the current status: sample image

I would like to use something like:

bquote(R(x[G]) == .(saleprice)%.%x[G] == .(revenue))

But it produces errors.

user2451870
  • 133
  • 1
  • 4
  • Huh, I never noticed before that R barfs on parsing chained comparison operators. It doesn't seem to mind anything else. Contrast `1 < 2 < 3` with `1 && 2 && 3`, `1 & 2 & 3`, or `x <- y <- z`, for example. – Hong Ooi Jun 04 '13 at 13:48
  • The reason why R doesn't like chained comparison operators is that ["it was decided that a == b == c would have undesirable semantics"](http://comments.gmane.org/gmane.comp.lang.r.general/326420) – gebi Dec 16 '15 at 09:25

1 Answers1

19

Use {} to put an invisible grouping around the first equality.

text(1, 2, bquote({R(x[G]) == .(saleprice)%.%x[G]} == .(revenue)))
Matthew Plourde
  • 43,932
  • 7
  • 96
  • 113