Skip to content
Prev 393580 / 398503 Next

return value of {....}

Fair enough, Akshay. Wondering why a design was chosen is reasonable.

 

There are languages like python that allow unpacking multiple values and it
is not uncommon to return multiple things from some constructs as in this:
4
5
6

 

But that is a bit of an illusion as the thing in curly braces is a very
different creature called a set with three items.  Python does not need or
use curly braces for the purposes used in R as indentation levels group
things.

 

It is different in design. I do not know what other computer languages you
have used, but R is NOT them and must be approached for what it is, and it
is a fairly simple paradigm for the last item in a sequence to be the value
of the sequence. You can return multiple things, if you wish, in other ways.
Such as making a list:

 

vals <- list(1+2, sin(.7), cos(.7))
[[1]]

[1] 0.6442177

 

[[2]]

[1] 0.7648422

 

You get the idea. R returns ONE thing and it ca have parts, named or not.

 

 

From: akshay kulkarni <akshay_e4 at hotmail.com> 
Sent: Tuesday, January 10, 2023 9:33 AM
To: avi.e.gross at gmail.com
Cc: 'R help Mailing list' <r-help at r-project.org>
Subject: Re: [R] return value of {....}

 

Dear Avi,

                 Thanks for your reply...your exhortations are indeed
justified...! But one caveat: I was not complaining about anything...just
was curious of the rationale of a particular design....Thanks again...

 

Thanking you,

Yours sincerely,

AKSHAY M KULKARNI   

  _____  

From: R-help <r-help-bounces at r-project.org
<mailto:r-help-bounces at r-project.org> > on behalf of avi.e.gross at gmail.com
<mailto:avi.e.gross at gmail.com>  <avi.e.gross at gmail.com
<mailto:avi.e.gross at gmail.com> >
Sent: Tuesday, January 10, 2023 4:39 AM
Cc: 'R help Mailing list' <r-help at r-project.org
<mailto:r-help at r-project.org> >
Subject: Re: [R] return value of {....} 

 

Akshay,

Your question seems a tad mysterious to me as you are complaining about
NOTHING.

R was designed to return single values. The last statement executed in a
function body, for example, is the value returned even when not at the end.

Scoping is another issue entirely. What is visible is another discussion.

So, yes, if you can see ALL the variables, you might see the last one BUT
there often is no variable at the end. There is an expression that evaluates
to a value with no NAME attached. You cannot reference that unless the block
in curly braces returns that value.

You can design your own language any way you want. The people who designed R
did it this way. Mind you, the most common use of curly braces is probably
in function bodies, or if/else blocks and loops, not quite what you are
looking at and complaining about. The design is what it is.

Others require things like an explicit return() statement. R chose not to.

And if the value is redundant for you, who cares?

Did you know that when running a program in the interpreter the last value
is stored in a variable like this:
[1] 6

Why would that duplicate be needed or useful?

Consider a partial calculation you want to reuse in another context:
[1] 10.5

Yes, you could have used "y" ...




-----Original Message-----
From: R-help <r-help-bounces at r-project.org
<mailto:r-help-bounces at r-project.org> > On Behalf Of akshay kulkarni
Sent: Monday, January 9, 2023 12:06 PM
To: Valentin Petzel <valentin at petzel.at <mailto:valentin at petzel.at> >
Cc: R help Mailing list <r-help at r-project.org <mailto:r-help at r-project.org>
Subject: Re: [R] return value of {....}

Dear Valentin,
                          But why should {....} "return" a value? It could
just as well evaluate all the expressions and store the resulting objects in
whatever environment the interpreter chooses, and then it would be left to
the user to manipulate any object he chooses. Don't you think returning the
last, or any value, is redundant? We are living in the 21st century world,
and the R-core team might,I suppose, have a definite reason for"returning"
the last value. Any comments?

Thanking you,
Yours sincerely,
AKSHAY M KULKARNI

Thread (32 messages)

akshay kulkarni return value of {....} Jan 9 Valentin Petzel return value of {....} Jan 9 Rui Barradas return value of {....} Jan 9 Bert Gunter return value of {....} Jan 9 akshay kulkarni return value of {....} Jan 9 akshay kulkarni return value of {....} Jan 9 Bert Gunter return value of {....} Jan 9 akshay kulkarni return value of {....} Jan 9 Andrew Simmons return value of {....} Jan 9 akshay kulkarni return value of {....} Jan 9 @vi@e@gross m@iii@g oii gm@ii@com return value of {....} Jan 9 Jeff Newmiller return value of {....} Jan 9 Bert Gunter return value of {....} Jan 9 akshay kulkarni return value of {....} Jan 10 @vi@e@gross m@iii@g oii gm@ii@com return value of {....} Jan 10 akshay kulkarni return value of {....} Jan 10 Richard O'Keefe return value of {....} Jan 10 akshay kulkarni return value of {....} Jan 11 Valentin Petzel return value of {....} Jan 12 Heinz Tuechler return value of {....} Jan 13 Bill Dunlap return value of {....} Jan 13 akshay kulkarni return value of {....} Jan 15 akshay kulkarni return value of {....} Jan 15 akshay kulkarni return value of {....} Jan 15 Richard O'Keefe return value of {....} Jan 15 Sorkin, John return value of {....} Jan 15 Bert Gunter return value of {....} Jan 15 Sorkin, John return value of {....} Jan 15 Bert Gunter return value of {....} Jan 15 @vi@e@gross m@iii@g oii gm@ii@com return value of {....} Jan 15 @vi@e@gross m@iii@g oii gm@ii@com return value of {....} Jan 15 Sorkin, John return value of {....} Jan 15