morphwj at comcast.net
2008-Sep-02 02:01 UTC
[R] How is the binding for a super assignment made visible?
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 been specified. 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. Bill Morphet ATK Space Systems, Launch Systems, Nozzle Structural Analysis
Thomas Lumley
2008-Sep-02 16:11 UTC
[R] How is the binding for a super assignment made visible?
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 Thomas Lumley Assoc. Professor, Biostatistics tlumley at u.washington.edu University of Washington, Seattle
Gabor Grothendieck
2008-Sep-02 16:33 UTC
[R] How is the binding for a super assignment made visible?
You could try using an assign statement instead: assign("Globals", list(), .GlobalEnv) and see if it complains about that or not. On Mon, Sep 1, 2008 at 10:01 PM, <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 been specified. > > 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. > > Bill Morphet > ATK Space Systems, Launch Systems, Nozzle Structural Analysis > > ______________________________________________ > R-help at 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. >
Reasonably Related Threads
- Why is package RandomFields not listed in the R 2.10.0 Packages list under Packages, Install package(s)...?
- R Extensions: Hyperlinking a pdf (not generated by Sweave/not a vignette) from a .Rd file
- Install from Local Zip
- Problem with lmer and wiki example
- Suggesting patch to link DOIs against secure resolver