but can, and
should be used when needed.
John
From: R-help on behalf of avi.e.gr...@gmail.com
Sent: Sunday, January 15, 2023 10:53 PM
Cc: 'R help Mailing list'
Subject: Re: [R] return value of {}
Again, John, we are comparing different designs
for verse.
-Original Message-
From: R-help On Behalf Of Sorkin, John
Sent: Sunday, January 15, 2023 8:08 PM
To: Richard O'Keefe ; Valentin Petzel
Cc: R help Mailing list
Subject: Re: [R] return value of {}
Richard,
I sent my prior email too quickly:
A slight addition to your code shows
Petzel
Cc: R help Mailing list
Subject: Re: [R] return value of {}
I wonder if the real confusino is not R's scope rules?
(begin .) is not Lisp, it's Scheme (a major Lisp dialect), and in Scheme,
(begin (define x ...) (define y ...) ...) declares variables x and y that
are local to the (begin
nction
> myfunction(y,b)
>
> Don't use the following code that depends on a global value that is known to
> the function, but not passed as a parameter to the function:
>
> y <- 2
> myNGfunction <- function(a){
> cat("a=",a,"b=",b,"\n")
>
know to the function,
# but should be passed as a parameter as in example above.
b <- 100
myNGfunction(y)
John
____
From: R-help on behalf of Sorkin, John
Sent: Sunday, January 15, 2023 7:40 PM
To: Richard O'Keefe; Valentin Petzel
Cc: R help Mailing
uld {} "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
> >
Richard O'Keefe
Sent: Sunday, January 15, 2023 6:39 PM
To: Valentin Petzel
Cc: R help Mailing list
Subject: Re: [R] return value of {}
I wonder if the real confusino is not R's scope rules?
(begin .) is not Lisp, it's Scheme (a major Lisp dialect),
and in Scheme, (begin (define x
s. 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,
3 9:18 PM
To: akshay kulkarni
Cc: R help Mailing list
Subject: Re: [R] return value of {}
Hello Akshai,
I think you are confusing {...} with local({...}). This one will evaluate the
expression in a separate environment, returning the last expression.
{...} simply evaluates multiple
Dear Bill,
Thanks for your reply.
thanking you,
Yours sincerely,
AKSHAY M KULKARNI
From: Bill Dunlap
Sent: Friday, January 13, 2023 10:48 PM
To: Valentin Petzel
Cc: akshay kulkarni ; R help Mailing list
Subject: Re: [R] return value
] return value of {}
> 09.01.2023 18:05:58 akshay kulkarni :
>
> We are living in the 21st century world, and the R-core team might,I suppose,
> have a definite reason ...
>
Maybe compatibility reasons with S and R-versions from the 20st century?
But maybe, you would have expec
From: Leonard Mada
Sent: Friday, January 13, 2023 1:44 AM
To: Akshay Kulkarni
Cc: R-help Mailing List
Subject: Re: [R] return value of {}
Dear Akshay,
The best response was given by Andrew. "{...}" is not a closure.
This is unusual for someone used to C-type
I suppose, have a definite
> reason for"returning" the last value. Any comments?
> >
> > Thanking you,
> > Yours sincerely,
> > AKSHAY M KULKARNI
> >
> >
> > *From:* Valentin Petzel
> > *Sent:* Monday, Ja
09.01.2023 18:05:58 akshay kulkarni :
We are living in the 21st century world, and the R-core team might,I suppose,
have a definite reason ...
Maybe compatibility reasons with S and R-versions from the 20st century?
But maybe, you would have expected some reason even then.
best regards,
--
> *From:* Valentin Petzel
> *Sent:* Monday, January 9, 2023 9:18 PM
> *To:* akshay kulkarni
> *Cc:* R help Mailing list
> *Subject:* Re: [R] return value of {}
>
> Hello Akshai,
>
> I think you are confusing {...} with local({...}). This one will ev
Dear Akshay,
The best response was given by Andrew. "{...}" is not a closure.
This is unusual for someone used to C-type languages. But I will try to
explain some of the rationale.
In the case that "{...}" was a closure, then external variables would
need to be explicitly declared before
O'Keefe
Sent: Wednesday, January 11, 2023 8:31 AM
To: akshay kulkarni
Cc: R help Mailing list
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
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
ubject: RE: [R] 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:
>>> a,b,c = { 4, 5, 6
t(1+2, sin(.7), cos(.7))
> vals[2:3]
[[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
Sent: Tuesday, January 10, 2023 9:33 AM
To: avi.e.gr...@gmail.com
Cc: 'R help Mailing list'
Subjec
From: R-help on behalf of avi.e.gr...@gmail.com
Sent: Tuesday, January 10, 2023 4:39 AM
Cc: 'R help Mailing list'
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
Hello Akshai,
I think you are confusing {...} with local({...}). This one will evaluate the
expression in a separate environment, returning the last expression.
{...} simply evaluates multiple expressions as one and returns the result of
the last line, but it still evaluates each expression.
"I suspect akshay is (or was? Not sure) unclear about what braces do.
They are not closures... they create an expression that wraps multiple
expressions into one expression... they are a little more like
parentheses than closures. They are not **intrinsically associated**
with creation of
I suspect akshay is (or was? Not sure) unclear about what braces do. They are
not closures... they create an expression that wraps multiple expressions into
one expression... they are a little more like parentheses than closures. They
are not intrinsically associated with creation of
Petzel
Cc: R help Mailing list
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 choos
Dear Andrew,
Nice point.
THanking you,
Yours sincerely,
AKSHAY M KULKARNI
From: Andrew Simmons
Sent: Monday, January 9, 2023 10:52 PM
To: akshay kulkarni
Cc: Valentin Petzel ; R help Mailing list
Subject: Re: [R] return value
anking you,
> Yours sincerely,
> AKSHAY M KULKARNI
>
>
> From: Valentin Petzel
> Sent: Monday, January 9, 2023 9:18 PM
> To: akshay kulkarni
> Cc: R help Mailing list
> Subject: Re: [R] return value of {}
>
> Hello Akshai,
>
> I think you are
___
From: Valentin Petzel
Sent: Monday, January 9, 2023 9:18 PM
To: akshay kulkarni
Cc: R help Mailing list
Subject: Re: [R] return value of {}
Hello Akshai,
I think you are confusing {...} with local({...}). This one will evaluate the
expression in a separate environment, returning
dear Rui,
Thanks a lot
Thanking you,
Yours sincerely,
AKSHAY M KULKARNI
From: Rui Barradas
Sent: Monday, January 9, 2023 9:48 PM
To: akshay kulkarni ; R help Mailing list
Subject: Re: [R] return value of {}
�s 14:47 de 09/01/2023
Perhaps the following may be of use to you.
Consider:
> f <- function(){ x <- 3; function(y) x+y}
> x <- 5
##What does this give?
> f()
## Why?
## How about this?
>f()(10)
## Why?
## If you remove "x <- 3" from the above, what will you get when you repeat
the exercise?
-- Bert
On Mon, Jan 9,
dear Bert,
Thanks a lot...
Thanking you,
Yours sincerely,
AKSHAY M KULKARNI
From: Bert Gunter
Sent: Monday, January 9, 2023 9:59 PM
To: akshay kulkarni
Cc: R help Mailing list
Subject: Re: [R] return value of {}
Unless you do something
Unless you do something special within a function, only the value(s)
returned are available to the caller. That is the essence of
functional-type programming languages.
You need to read up on (function) environments in R . You can search on
this. ?function and its links also contain useful
Às 14:47 de 09/01/2023, akshay kulkarni escreveu:
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
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
A long time ago (before the mid-1990's?) with S or S+
ff <- function(n){ for(i in 1:n) (i+1)
op <- ff(3)
would result in 'op' being 4, since a for-loop's value
was the value of the last expression executed in the
body of the loop. The presence of a 'next' or 'break'
in the loop body would
Ramnik,
a final mail is actually really important: this is to document in the archives,
for the benefit of those who found the thread at a later time, that the
responses indeed solved the problem.
Other than that, the single most important advice is to
- provide a minimal working example of
(Apparently I hit "send" too early)
1. I have cc'ed this to the list, as others may well have some good
suggestions re: books.
2. The posting guide is your best resource as to what is appropriate
for the list. I defer to others re: conventions, as I have have been
accused of violating them from
OK. I stand corrected. Thanks.
-- Bert
Bert Gunter
"The trouble with having an open mind is that people keep coming along
and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
On Sun, Apr 16, 2017 at 11:36 PM, David Winsemius
> On 17 Apr 2017, at 10:04 , Ramnik Bansal wrote:
>
> This is my output for is.function
>
>> is.function("for")
> [1] FALSE
>> is.function(for)
> Error: unexpected ')' in "is.function(for)"
>> is.function("next")
> [1] FALSE
>> is.function(next)
> Error: no loop for
This is my output for is.function
> is.function("for")
[1] FALSE
> is.function(for)
Error: unexpected ')' in "is.function(for)"
> is.function("next")
[1] FALSE
> is.function(next)
Error: no loop for break/next, jumping to top level
*I did not get the TRUE value. R version 3.3.3 on Mac. What am I
Both 'for' and 'next' return TRUE from is.function
is.function('for')
is.function('next')
Not at an R console at the moment but I did check this earlier today. Thinking
of it as different is definitely the way to think about it. (ISTR Bert and I
have had this exchange in the past.)
--
Best
David et. al.:
"this levels is the level where you realize that the `for` function is
different from most other R functions. It is really a
side-effect-fucntion. "
for(), while(), if(), next, etc. are *not* functions.
?for says: "These are the basic control-flow constructs of the R language."
> On Apr 16, 2017, at 7:26 PM, Ramnik Bansal wrote:
>
> In the code below
>
>
> *ff <- function(n){ for(i in 1:n) (i+1)}*
>
> *n<-3;ff(n)->op;print(op)*
>
> Why doesnt *print(op) * print 4 and instead prints NULL.
> Isnt the last line of code executed is *i+1 * and
In the first case you have a "for" and it is the statement after the
'for' that is the return value and it is a NULL. For example:
> print(for (i in 1:4) i+1)
NULL
In the second case, the last statement if the expression '(n+1)' which
give you the correct value:
> xx <- function(n) n+1
>
In the code below
*ff <- function(n){ for(i in 1:n) (i+1)}*
*n<-3;ff(n)->op;print(op)*
Why doesnt *print(op) * print 4 and instead prints NULL.
Isnt the last line of code executed is *i+1 * and therefore that should be
returned instead of NULL
instead if I say
*ff <- function(n){ (n+1) }*
Ulrich wrote:
Hi,
is it possible to easily change the return value for the grep function
for cases where there is no match, for example the value 0 or No
instead of integer (0) )?
It sounds like you might want grepl (which returns a vector of TRUE and
FALSE values) rather than grep
Hi,
is it possible to easily change the return value for the grep function
for cases where there is no match, for example the value 0 or No
instead of integer (0) )?
Thanks, Uli
__
R-help@r-project.org mailing list
On Oct 30, 2010, at 10:51 PM, Ulrich wrote:
Hi,
is it possible to easily change the return value for the grep
function for cases where there is no match, for example the value 0
or No instead of integer (0) )?
Seems like is should be pretty easy. Test for length(grep(...)) == 0
or
On Sat, Oct 30, 2010 at 10:51 PM, Ulrich ulrich.schle...@stanford.edu wrote:
Hi,
is it possible to easily change the return value for the grep function for
cases where there is no match, for example the value 0 or No instead of
integer (0) )?
Try this:
Find(length, list(grep(X, letters),
On Oct 30, 2010, at 11:13 PM, David Winsemius wrote:
On Oct 30, 2010, at 10:51 PM, Ulrich wrote:
Hi,
is it possible to easily change the return value for the grep
function for cases where there is no match, for example the value 0
or No instead of integer (0) )?
Seems like is
I am using the code below to extract census tract information.
save.tract$state, save.tract$county and save.tract$tract are returned as
factors. In the last three statements, I need to save the actual value of
the factor, but, instead, the code is yielding the position of the factor.
How do I
Code is not runnable, so can't check why it goes wrong, but tried
already with as.character(save.tract$...) ?
Cheers
Joris
On Mon, Jun 21, 2010 at 3:15 PM, GL pfl...@shands.ufl.edu wrote:
I am using the code below to extract census tract information.
save.tract$state, save.tract$county and
Works great. Thanks much!
--
View this message in context:
http://r.789695.n4.nabble.com/Return-value-associated-with-a-factor-tp2262605p2262656.html
Sent from the R help mailing list archive at Nabble.com.
__
R-help@r-project.org mailing list
Dear R-users,
I'm trying to call the qgamma function from a C program.
But I'm experiencing a strange issue: the value returned by the C function
seems to be different from the value returned by a R console.
I'm running on linux 2.6.27 (ubuntu), i686 arch; R version 2.7.1 (2008-06-23)
(shipped
Hello,
I have the TCl/Tk command
tkmessageBox(titel=,message=x,icon=question,type=okcancel) in my R
script. Now I want to perform some operation in relation to the user's
choice, something like
if (okpressed) xxx else yyy
What values does this command give and how are they used?
Thank you,
Is it so hard to find out?
Your tcl documentation will tell you what tk_messageBox returns, and as it
is tcl string, you need to call tclvalue() on the value of tkmessageBox()
to get an R character vector.
On Fri, 28 Dec 2007, Richard Müller wrote:
Hello,
I have the TCl/Tk command
Richard Müller wrote:
I have the TCl/Tk command
tkmessageBox(titel=,message=x,icon=question,type=okcancel)
in my R script. Now I want to perform some operation in relation to
the user's choice, something like if (okpressed) xxx else yyy What
values does this command give and how are they
This webpage has been very helpful for me:
http://bioinf.wehi.edu.au/~wettenhall/RTclTkExamples/
-Samu
Richard Müller kirjoitti:
Hello,
I have the TCl/Tk command
tkmessageBox(titel=,message=x,icon=question,type=okcancel) in my R
script. Now I want to perform some operation in relation to
res - tkmessageBox(title = test,message = Continue?,
+icon =question, type = okcancel)
if (tclvalue(res) == ok) 1 else 2
Happy new year!
Philippe Grosjean
Richard Müller wrote:
Hello,
I have the TCl/Tk command
tkmessageBox(titel=,message=x,icon=question,type=okcancel) in my R
59 matches
Mail list logo