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. 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? 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. When I execute the statement interactively, even in the debugger in the function that executes the statement, it seems to work. But if it executes in the function, gcv appears to remain unset. I assume gcv is getting set in some other frame, but where it is and how to track it down I don't know. In an effort to get around this I did gcv <- list() in the global namespace (on the distributed nodes), but this doesn't seem to help. I'm just left with the empty list, even after calls to crossval.setup. Any ideas? Thanks.
Prof Brian Ripley
2003-Apr-26 07:26 UTC
[R] Problme with <<- (was Apparent namespace problem)
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
Ross - Inside whatever function defines the variable gcv, do: assign("gcv", gcv, 1) after you've defined gcv and before the function exits. help("assign") gives other ways to specify the target namespace (not all of which I quite understand). My hunch is this has nothing to do with snow or the cluster architecture. (I could be totally wrong.) - tom blackwell - u michigan medical school - ann arbor - 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. > > 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? > > 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. > > When I execute the statement interactively, even in the debugger > in the function that executes the statement, it seems to work. > But if it executes in the function, gcv appears to remain unset. > > I assume gcv is getting set in some other frame, but where it is > and how to track it down I don't know. > > In an effort to get around this I did gcv <- list() in the global > namespace (on the distributed nodes), but this doesn't seem to help. > I'm just left with the empty list, even after calls to crossval.setup. > > Any ideas?