Just one correction. The line environment(fun.global) <- environment()
line below should be deleted. It was needed in a prior example but in this one
we use parent.frame()$setVar(4) in the call so that line is not needed in main.

On Fri, Aug 21, 2009 at 7:09 AM, Gabor
Grothendieck<ggrothendi...@gmail.com> wrote:
> Yet another possibility is to simply mandate that the user call setVar
> directly from fun.global and ask them to do it like this:
>
> fun.global <- function() parent.frame()$setVar(4)
> main <- function() {
>       l.var <- 0
>       setVar <- function(value) { message("set Var"); l.var <<- value }
>       environment(fun.global) <- environment()
>       fun.global()
>       print(l.var)
> }
> main()

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to