[R] How is the binding for a super assignment made visible?

Thomas Lumley tlumley at u.washington.edu
Tue Sep 2 18:11:00 CEST 2008

On Tue, 2 Sep 2008 morphwj at comcast.net wrote:

> The statement Globals <<- list() in the body of a function in a package was
> intended to write an empty list to the R workspace to collect results during 
> the computations of the function.  A package name space has not beenspecified.
> The package appears to function correctly, but
> during the R CMD check of the package while "checking R code for possible
> problems ... NOTE",
> no visible binding for '<<-' assignment to 'Globals' is displayed.
> Can you tell in this case why the binding needs to be visible?  What
> statement might do that?  A specific reference in the R manuals would be
> appreciated.

The message really parses as "no binding (as far as we can see)" - it's a request for a binding, not a request for visibility. It's phrased that way because it is possible to have false positives in this code -- variables that really have been previously defined, but don't look as if they have.

You are using <<- on a variable that doesn't appear to have been previously defined in your code.  In fact, as you tell us, it wasn't previously defined, so the note is correct.  This isn't an error, but is often a bad idea: the assignment will overwrite any existing variable called Globals that happens to be in the workspace.

One alternative (since you don't have a namespace) would be to define a variable
   Globals <- list()
at the top level in your package.  The superassignments would then modify that variable.


Thomas Lumley			Assoc. Professor, Biostatistics
tlumley at u.washington.edu	University of Washington, Seattle

More information about the R-help mailing list