[Rd] globalVariables()

John Fox jfox at mcmaster.ca
Sat Jun 23 17:51:55 CEST 2012

Dear r-devel list members,

By placing a call to the new (with R 2.15.1) globalVariables() in the development version of the Rcmdr package, I've succeeded in reducing the "notes" produced by R CMD check from dozens to two. But I still get the following notes, even though '.commander.done' is in the call to globalVariables():

------------- snip ------------

* checking R code for possible problems ... NOTE
Commander: no visible binding for '<<-' assignment to '.commander.done'
  (C:/Users/John Fox/workspace/Rcmdr/R/commander.R:653)
closeCommander: no visible binding for '<<-' assignment to
  '.commander.done' (C:/Users/John

------------- snip ------------

Is there a way to get rid of these notes (without, of course, removing the <<- assignments)?

Finally, here's a rough function that I used to compose the globalVariables() command from the package check summary; it's probably not bullet-proof, but perhaps others will find it useful for packages, like the Rcmdr, that currently generate many notes about global variables:

------------- snip ------------

findGlobals <- function(filein="00check.log", fileout="globals.R"){
  checklog <- readLines(filein)
  whichline <- which(grepl("checking R code for possible problems .* NOTE", checklog))
  checklog <- checklog[-(1:whichline)]
  whichline <- which(grepl("checking Rd files", checklog))
  checklog <- checklog[-(whichline:length(checklog))]
  globals <- gsub(".*no visible binding for global variable[ ]*", "", checklog)
  globals <- gsub(".*no visible global function definition for[ ]*", "", globals)
  globlas <- gsub(".*no visible binding for '<<-' assignment to[ ]*", "", globals)
  globals <- globals[globals != ""]
  globals <- sub("^ *", "", globals)
  globals <- sub(" *$", "", globals)
  whichentries <- which(grepl(":", globals))
  globals <- globals[-whichentries]
  globals <- gsub(".* ", "", globals)
  globals <- unique(globals)
  cmd <- paste("if (getRversion() >= '2.15.1') globalVariables(c(", 
               paste(globals, collapse=", "), "))", sep="")
  cmd <- strwrap(cmd)
  writeLines(cmd, fileout)

------------- snip ------------

Any help would be appreciated.


John Fox
Sen. William McMaster Prof. of Social Statistics
Department of Sociology
McMaster University
Hamilton, Ontario, Canada

More information about the R-devel mailing list