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

2023-01-15 Thread Sorkin, John
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

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

2023-01-15 Thread avi.e.gross
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

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

2023-01-15 Thread avi.e.gross
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

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

2023-01-15 Thread Bert Gunter
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") >

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

2023-01-15 Thread Sorkin, John
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

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

2023-01-15 Thread Bert Gunter
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 > >

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

2023-01-15 Thread Sorkin, John
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

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

2023-01-15 Thread Richard O'Keefe
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,

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

2023-01-15 Thread akshay kulkarni
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

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

2023-01-15 Thread akshay kulkarni
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

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

2023-01-15 Thread akshay kulkarni
] 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

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

2023-01-15 Thread akshay kulkarni
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

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

2023-01-13 Thread Bill Dunlap
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

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

2023-01-13 Thread Heinz Tuechler
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,

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

2023-01-13 Thread Valentin Petzel
-- > *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

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

2023-01-12 Thread Leonard Mada via R-help
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

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

2023-01-11 Thread akshay kulkarni
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

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

2023-01-10 Thread Richard O'Keefe
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

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

2023-01-10 Thread akshay kulkarni
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

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

2023-01-10 Thread avi.e.gross
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

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

2023-01-10 Thread akshay kulkarni
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

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

2023-01-10 Thread Valentin Petzel
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.

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

2023-01-09 Thread Bert Gunter
"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

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

2023-01-09 Thread Jeff Newmiller
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

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

2023-01-09 Thread avi.e.gross
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

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

2023-01-09 Thread akshay kulkarni
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

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

2023-01-09 Thread Andrew Simmons
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

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

2023-01-09 Thread akshay 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 confusing {...} with local({...}). This one will evaluate the expression in a separate environment, returning

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

2023-01-09 Thread akshay kulkarni
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

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

2023-01-09 Thread Bert Gunter
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,

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

2023-01-09 Thread akshay kulkarni
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

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

2023-01-09 Thread Bert Gunter
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

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

2023-01-09 Thread Rui Barradas
À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

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

2023-01-09 Thread akshay kulkarni
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

Re: [R] Return value from function with For loop

2017-04-17 Thread William Dunlap via R-help
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

Re: [R] Return value from function with For loop

2017-04-17 Thread Boris Steipe
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

Re: [R] Return value from function with For loop

2017-04-17 Thread Bert Gunter
(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

Re: [R] Return value from function with For loop

2017-04-17 Thread Bert Gunter
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

Re: [R] Return value from function with For loop

2017-04-17 Thread peter dalgaard
> 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

Re: [R] Return value from function with For loop

2017-04-17 Thread Ramnik Bansal
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

Re: [R] Return value from function with For loop

2017-04-17 Thread David Winsemius
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

Re: [R] Return value from function with For loop

2017-04-16 Thread Bert Gunter
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."

Re: [R] Return value from function with For loop

2017-04-16 Thread David Winsemius
> 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

Re: [R] Return value from function with For loop

2017-04-16 Thread jim holtman
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 >

[R] Return value from function with For loop

2017-04-16 Thread Ramnik Bansal
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) }*

Re: [R] return value for grep

2010-10-31 Thread Duncan Murdoch
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

[R] return value for grep

2010-10-30 Thread Ulrich
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

Re: [R] return value for grep

2010-10-30 Thread David Winsemius
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

Re: [R] return value for grep

2010-10-30 Thread Gabor Grothendieck
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),

Re: [R] return value for grep

2010-10-30 Thread David Winsemius
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

[R] Return value associated with a factor

2010-06-21 Thread GL
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

Re: [R] Return value associated with a factor

2010-06-21 Thread Joris Meys
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

Re: [R] Return value associated with a factor

2010-06-21 Thread GL
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

[R] Return value from a C program is different from the R console

2009-03-24 Thread Loïc Paulevé
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

[R] Return Value of TCl/Tk window in R

2007-12-28 Thread Richard Müller
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,

Re: [R] Return Value of TCl/Tk window in R

2007-12-28 Thread Prof Brian Ripley
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

Re: [R] Return Value of TCl/Tk window in R

2007-12-28 Thread Alberto Monteiro
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

Re: [R] Return Value of TCl/Tk window in R

2007-12-28 Thread Samu Mäntyniemi
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

Re: [R] Return Value of TCl/Tk window in R

2007-12-28 Thread Philippe Grosjean
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