[R] return value of {....}

akshay kulkarni @k@h@y_e4 @end|ng |rom hotm@||@com
Wed Jan 11 18:04:41 CET 2023


Dear Richard,
                        Thanks for your reply. As replied to Avi, i was not complaining, just inquiring: was just curious to know the rationale for the design of {...}, thas all...!

Thanking you,
Yours sincerely,
AKSHAY M KULKARNI
________________________________
From: Richard O'Keefe <raoknz using gmail.com>
Sent: Wednesday, January 11, 2023 8:31 AM
To: akshay kulkarni <akshay_e4 using hotmail.com>
Cc: R help Mailing list <r-help using r-project.org>
Subject: Re: [R] return value of {....}

I am more than a little puzzled by your question.
In the construct {expr1; expr2; expr3} all of the
expressions expr1, expr2, and expr3 are evaluated,
in that order.  That's what curly braces are FOR.
When you want some expressions evaluated in a
specific order, that's why and when you use curly
braces.  If that's not what you want, don't use them.
Complaining about it is like complaining that + adds.


On Tue, 10 Jan 2023 at 03:47, akshay kulkarni <akshay_e4 using hotmail.com<mailto:akshay_e4 using hotmail.com>> wrote:
Dear members,
                             I have the following code:

> TB <- {x <- 3;y <- 5}
> TB
[1] 5

It is consistent with the documentation: For {, the result of the last expression evaluated. This has the visibility of the last evaluation.

But both x AND y are created, but the "return value" is y. How can this be advantageous for solving practical problems? Specifically, consider the following code:

F <- function(X) {  expr; expr2; { expr5; expr7}; expr8;expr10}

Both expr5 and expr7 are created, and are accessible by the code outside of the nested braces right? But the "return value" of the nested braces is expr7. So doesn't this mean that only expr7 should be accessible? Please help me entangle this (of course the return value of F is expr10, and all the other objects created by the preceding expressions are deleted. But expr5 is not, after the control passes outside of the nested braces!)

Thanking you,
Yours sincerely,
AKSHAY M KULKARNI

        [[alternative HTML version deleted]]

______________________________________________
R-help using r-project.org<mailto:R-help using r-project.org> mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

	[[alternative HTML version deleted]]



More information about the R-help mailing list