[R] Problme with <<- (was Apparent namespace problem)
Prof Brian Ripley
ripley at stats.ox.ac.uk
Sat Apr 26 09:26:39 CEST 2003
On Fri, 25 Apr 2003, Ross Boylan wrote:
> I'm seeing some strange behavior while using the snow package for
> networked computers. I believe it's caused by name space resolution
> issues, and would appreciate any suggestions tracking it down.
`namespace' is a technical term in R (some packages have namespaces), and
not I think involved here. I think you meant `scoping issues', although
the exact issue seems to be an inappropriate use of <<-.
> First, is there a way to find out what frame (as in frames in
> environments, not data frames) a name is being obtained from or put
> into?
?find.
> Second, how closely does the evaluation environment in the
> browser/debugger match what you would get in the function at the same
> point? I ask because if I evaluate a statement in the browser it
> seems to work one way, but if I execute it it works another way.
>
> The statement is
> clusterEvalQ(cl, crossval.setup(x, y, groups, theta.fit,
> theta.predict))
>
> This evaluates the crossval.setup function across the cluster cl.
>
> crossval.setup is a function which puts its arguments in a list g (a
> local variable) and then does gcv <<- g. The intent is to stuff the
> data into a global variable for use by later function calls.
If that is the intention, please use assign() explicitly. That is not
what <<- is intended to do in R and it probably should only be used to
change an already existing value somewhere in the environment tree.
assign("gcv", g, envir=NULL), I believe
[...]
I have ignored the `snow' aspect, as I don't understand enough of how you
are using it: it might be relevant.
--
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595
More information about the R-help
mailing list