[R] Problme with <<- (was Apparent namespace problem)

Ross Boylan ross at biostat.ucsf.edu
Tue Apr 29 00:25:04 CEST 2003

I'd like to thank both Thomas Blackwell and Brian Ripley for their help.

The source of the problem was a snow-related think-o
	clusterEvalQ(cl, crossval.setup(x, y, groups, theta.fit,
evaluates crossval.setup on remote nodes, using the values of x, y,
etc *on those nodes*.  But this was precisely the data that was to be
distributed.  So the call failed, and the assignment statement never
had a chance to execute.

For those who follow, I note the proper code is
      clusterCall(cl, crossval.setup,
			x, y, groups, theta.fit, theta.predict)

I do have a couple more comments and questions on the message below,
if anyone would care to respond.

On Sat, Apr 26, 2003 at 08:26:39AM +0100, Prof Brian Ripley wrote:
> 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 <<-.

Yes, it's scoping.  I was using namespace generically.

I'm not sure what the best way is to describe the actual problem I
had, namely that variables known on one the parent node were not known
on the child.  "scoping" seems to imply a single process on a single
machine, and "namespace" is already taken for something else.

> > 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.

Here's where I have a question.  find appears to operate on the search
path.  I thought that was a different concept from environments and
frames.  The search path, I think, doesn't include dynamically created
frames from the course of function execution.

> > 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.

As a precaution, I had created the variable in the global space.

> assign("gcv", g, envir=NULL), I believe

I used pos=.GlobalEnv

> [...]
> I have ignored the `snow' aspect, as I don't understand enough of how you 
> are using it: it might be relevant.

Yes, it was.

> -- 
> 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