[Rd] globalVariables()
John Fox
jfox at mcmaster.ca
Sun Jun 24 16:57:46 CEST 2012
Dear r-devel list members,
To answer my own question, replacing <<- with explicit assign()s seem to do the trick.
As well, the quickly written function that I posted had a couple of problems (and may well have more, though the version posted below works on the packages I tried); here's an improved version:
----------- 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)
globals <- gsub(".*no visible binding for '<<-' assignment to[ ]*", "", globals)
globals <- globals[globals != ""]
globals <- sub("^ *", "", globals)
globals <- sub(" *$", "", globals)
whichentries <- which(grepl(":", globals))
if (length(whichentries > 1)) 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 -----------
Best,
John
On Sat, 23 Jun 2012 11:51:55 -0400
"John Fox" <jfox at mcmaster.ca> wrote:
> 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
> Fox/workspace/Rcmdr/R/file-menu.R:142)
>
> ------------- 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:
>
. . .
>
> Any help would be appreciated.
>
> John
>
> ------------------------------------------------
> John Fox
> Sen. William McMaster Prof. of Social Statistics
> Department of Sociology
> McMaster University
> Hamilton, Ontario, Canada
> http://socserv.mcmaster.ca/jfox/
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
More information about the R-devel
mailing list