[Rd] globalVariables()

From: John Fox <jfox_at_mcmaster.ca>
Date: Sat, 23 Jun 2012 11:51:55 -0400

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():

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:

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)

Any help would be appreciated.


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

R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Sat 23 Jun 2012 - 16:01:49 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sun 24 Jun 2012 - 05:50:30 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive