On Thu, 13 Apr 2006, Rolf Turner wrote:

> Brian Ripley wrote:
>
>> Can I also suggest local()?  This does a similar thing in a perhaps
>> more natural way.
>
> Sorry, I'm not with you.  I'm slow, and as I said, I don't
> really grok environments.
>
> Let's look at a toy example.  Suppose I want to create a function foo:
>
>       function(x){x^n}
>
> and assign n the value of 4, say, in the environment of foo.
>
> Duncan Murdoch's solution was to create a function make.foo:
>
>       make.foo <- function() {
>               n <- 4
>               foo <- function(x){x^n}
>               foo
>       }
>
> and then execute
>
>       foo <- make.foo()
>
> How would I go about accompishing the same (toy) task making use of the
> local() function?
>
         foo <- local({
                       n <- 4
                       function(x) {x^n}
                     })

       -thomas


Thomas Lumley                   Assoc. Professor, Biostatistics
[EMAIL PROTECTED]       University of Washington, Seattle

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

Reply via email to