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
ust 6, 2012 5:07 PM
Subject: [R] Force evaluation of a symbol when a function is created
I am porting a program in matlab to R,
The problem is that Matlab has a feature where symbols that aren't arguments
are evaluated immediately.
That is:
Y=3
F=@(x) x*Y
Will yield a function such that F(2)
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.
>
Message-
>> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
>> Behalf
>> Of Schoenfeld, David Alan,Ph.D.,Biostatistics
>> Sent: Monday, August 06, 2012 2:08 PM
>> To: 'r-help@r-project.org'
>> Subject: [R] Force evalua
---Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
> Behalf
> Of Schoenfeld, David Alan,Ph.D.,Biostatistics
> Sent: Monday, August 06, 2012 2:08 PM
> To: 'r-help@r-project.org'
> Subject: [R] Force evaluation of a symbo
I am porting a program in matlab to R,
The problem is that Matlab has a feature where symbols that aren't arguments
are evaluated immediately.
That is:
Y=3
F=@(x) x*Y
Will yield a function such that F(2)=6.
If later say. Y=4 then F(2) will still equal 6.
R on the other hand has lazy evaluation.
11 matches
Mail list logo