[R] Environmental problems.
Rolf Turner
r.turner at auckland.ac.nz
Tue Feb 25 23:19:55 CET 2014
On 26/02/14 00:56, Enrico Schumann wrote:
<SNIP>
>
> I did not follow your example, neither do I use the deSolve package; but
> why not pass an environment as an argument?
>
> ## some iterative function that takes another fun as argument
> outer <- function(fun, ...) {
> for (i in 1:20)
> fun(...)
> }
>
> ## create an environment ...
> info <- new.env()
> info$tt <- 0
>
> ## ... and pass it as an argument
> myfun <-function(e) {
> e$tt <- e$tt + 1
> cat("Iteration ", e$tt, "\n")
> }
>
> outer(myfun, info)
> info$tt
>
Sounds like a good idea. Tried it. Got exactly the same phenomenon as
with my idea. The "tdone" variable stays equal to 0 and there is no
progress report (as desired) until time gets up to 0.1. Then tdone gets
re-set to the value of tt *every* call, so that tt - tdone is always
equal to 0 and there are no further progress reports.
I have attached a tar-ball and a zip archive both containing the
necessary code to demonstrate the forgoing. Unpack, source all the *.R
files and then source "demoScript" to see it happen before your very
eyes. :-)
cheers,
Rolf Turner
More information about the R-help
mailing list