Re: [R] Force evaluation of a symbol when a function is created

2012-08-07 Thread Bert Gunter
Thanks Duncan. That clarifies it! -- Bert On Tue, Aug 7, 2012 at 12:28 PM, Duncan Murdoch wrote: > On 12-08-07 10:46 AM, Bert Gunter wrote: >> >> Duncan, et.al: >> >> Many thanks: let the closure do the work automatically rather than >> manually manipulating it. >> >> However, in the spirit of t

Re: [R] Force evaluation of a symbol when a function is created

2012-08-07 Thread Duncan Murdoch
On 12-08-07 10:46 AM, Bert Gunter wrote: Duncan, et.al: Many thanks: let the closure do the work automatically rather than manually manipulating it. However, in the spirit of the OP's original request, I believe the call would be: Y <- 3 ## That is, Y gets a value at some prior point, perhap

Re: [R] Force evaluation of a symbol when a function is created

2012-08-07 Thread Bert Gunter
Duncan, et.al: Many thanks: let the closure do the work automatically rather than manually manipulating it. However, in the spirit of the OP's original request, I believe the call would be: >Y <- 3 ## That is, Y gets a value at some prior point, perhaps >programmatically. > F <- multiply_by_

Re: [R] Force evaluation of a symbol when a function is created

2012-08-07 Thread Duncan Murdoch
Here's one more way. It seems to me this is the most R-like way to do what you want: multiply_by_Y <- function(Y) { force(Y) function(x) x*Y } F <- multiply_by_Y(3) The "force" call forces Y to be evaluated at that point, so its value is fixed from that point forward. Duncan

Re: [R] Force evaluation of a symbol when a function is created

2012-08-06 Thread arun
Hi, Try this:  F<-function(x,type="local"){Y=3  x*Y} F(3) #[1] 9  Y<-4  F(3) #[1] 9  Y<-5  F(3) #[1] 9 A.K. - Original Message - From: "Schoenfeld, David Alan,Ph.D.,Biostatistics" To: "'r-help@r-project.org'" Cc: Sent: Monday, August 6, 2012 5:07 PM Subject: [R] Force evaluation of

Re: [R] Force evaluation of a symbol when a function is created

2012-08-06 Thread R. Michael Weylandt
On Mon, Aug 6, 2012 at 9:03 PM, Schoenfeld, David Alan,Ph.D.,Biostatistics wrote: > Thank you both, this was very helpful. I need to study environments more. Do > either of you know a good source? Disclaimer: I really have no idea what I'm talking about. They are a somewhat subtle, but excepti

Re: [R] Force evaluation of a symbol when a function is created

2012-08-06 Thread Schoenfeld, David Alan,Ph.D.,Biostatistics
; r-help@r-project.org Subject: Re: [R] Force evaluation of a symbol when a function is created Thanks to both: Cute question, clever, informative answer. However, Bill, I don't think you **quite** answered him, although the modification needed is completely trivial. Of course, I could never

Re: [R] Force evaluation of a symbol when a function is created

2012-08-06 Thread William Dunlap
ne.com] > Sent: Monday, August 06, 2012 3:03 PM > To: William Dunlap > Cc: Schoenfeld, David Alan,Ph.D.,Biostatistics; r-help@r-project.org > Subject: Re: [R] Force evaluation of a symbol when a function is created > > Thanks to both: Cute question, clever, informative answer. >

Re: [R] Force evaluation of a symbol when a function is created

2012-08-06 Thread Bert Gunter
Thanks to both: Cute question, clever, informative answer. However, Bill, I don't think you **quite** answered him, although the modification needed is completely trivial. Of course, I could never have figured it out without your response. Anyway, I interpret the question as asking for the functi

Re: [R] Force evaluation of a symbol when a function is created

2012-08-06 Thread William Dunlap
You could use local(), as in > F <- local({ +Y <- 3 +function(x) x * Y +}) >F(7) [1] 21 > Y <- 19 > F(5) [1] 15 Look into 'environments' for more. Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com > -Original Message- > From: r-help