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
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
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_
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
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
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
; 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
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.
>
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
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
10 matches
Mail list logo