0

In R, I can do:

{1+1; 2+2; 3+3}

or, if you prefer:

{1+1
 2+2
 3+3}

Perhaps not surprisingly, both of these (compound) expressions evaluate to 6.

Is this a (documented) feature of the R language, that the value of a compound expression is equal to the last evaluated statement in the compound expression?

The official documentation is light on the topic: http://cran.r-project.org/doc/manuals/r-release/R-lang.html#Compound-expressions

Al R.
  • 2,430
  • 4
  • 28
  • 40
  • 1
    The answer is yes. Notice that cited section correctly predicts results of `is.function(` applied to a back-ticked `{`, i.e.`TRUE`. You can also use this to demonstrate that the tilde-operator (`~`) is also parsed as a function. – IRTFM Jan 24 '15 at 01:00

1 Answers1

1

I see that this is in fact the documented behavior: http://cran.r-project.org/doc/manuals/r-release/R-lang.html#Evaluation-of-expression-objects

Al R.
  • 2,430
  • 4
  • 28
  • 40
  • 1
    The other clue is that in the original link you provided is says that "internally, [compound expressions are] stored as a function call" and functions return the result of the last evaluated expression. – MrFlick Jan 23 '15 at 21:00