If you want to use this pattern repeatedly you can define something like
makeFunWithCounter <- function(fun) {
counter <- 0
list(count = function() counter,
fun = function(...) { counter <<- counter + 1; fun(...)})
}
and then do
> fwc <- makeFunWithCount
Thanks,
I think I over-emphasized the secondary function, but I can generate the
scoping problem as follows. First, at the command line, I can get a
function to access objects that were not in its arguments by
ProfileEnv = new.env()
hello.world = "Hello World"
assign('hello.world',hello.worl
On 29/08/2008 6:52 AM, Giles Hooker wrote:
Thanks,
I think I over-emphasized the secondary function, but I can generate the
scoping problem as follows. First, at the command line, I can get a
function to access objects that were not in its arguments by
ProfileEnv = new.env()
hello.world = "H
From: "Duncan Murdoch" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Cc:
Sent: Thursday, August 28, 2008 5:42 AM
Subject: Re: [Rd] Defining environments within functions
Giles Hooker wrote:
How can I define environments within a function so that they are visible
to c
Giles Hooker wrote:
How can I define environments within a function so that they are visible
to calls to a sub-function?
I think you need to give a simplified, runnable example. (Or at least
runnable until it hits the scoping problem you've got.) "Sub-function"
isn't R terminology, and i
How can I define environments within a function so that they are visible
to calls to a sub-function?
I have defined an objective function,
ProfileErr = function(params,...)
which I would like to optimize using standard routines (optim,
nlminb,) but which contains auxiliary variables