Re: [Rd] globalVariables()

From: John Fox <jfox_at_mcmaster.ca>
Date: Sun, 24 Jun 2012 10:57:46 -0400

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:

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)
}

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



R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Sun 24 Jun 2012 - 15:02:32 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 Mon 25 Jun 2012 - 14:30: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