[Rd] no visible binding for global variable for data sets in a package

Michael Friendly friendly at yorku.ca
Wed Aug 27 16:07:04 CEST 2014


On 8/27/2014 9:29 AM, Michael Friendly wrote:
>> It works in the sense that  Lahman::Label("yearID")  will
>> work even when Lahman is not in the search path,
>> but   R-devel CMD check   will still give the same NOTE,
>> though you can argue that that note is actally a "false positive".
> So, this would be version 1 of "2)":
>
> Label <- function(var, labels) {
>      stopifnot(require(Lahman, quietly=TRUE))
>      if(missing(labels)) labels <- rbind(battingLabels, pitchingLabels,
> fieldingLabels)
>      wanted <- which(labels[,1]==var)
>      if (length(wanted)) labels[wanted[1],2] else var
> }
>
> And this would be version 2, using data():
>
> Label <- function(var, labels) {
>      stopifnot(require(Lahman, quietly=TRUE))
>      if(missing(labels)) {
>          data(battingLabels); data(pitchingLabels); data(fieldingLabels)
>          labels <- rbind(battingLabels, pitchingLabels, fieldingLabels)
>          }
>      wanted <- which(labels[,1]==var)
>      if (length(wanted)) labels[wanted[1],2] else var
> }
>
>

Just to follow up:  R-devel likes this less than it does my initial 
version.  I still get no visible binding NOTES, and complaint about
using data() in a function:

* checking R code for possible problems ... NOTE
Label: no visible binding for global variable 'battingLabels'
Label: no visible binding for global variable 'pitchingLabels'
Label: no visible binding for global variable 'fieldingLabels'
battingStats: no visible binding for global variable 'Batting'
battingStats: no visible global function definition for 'mutate'
playerInfo: no visible binding for global variable 'Master'
teamInfo: no visible binding for global variable 'Teams'

Found the following calls to data() loading into the global environment:
File 'Lahman/R/Label.R':
   data(battingLabels)
   data(pitchingLabels)
   data(fieldingLabels)
See section 'Good practice' in '?data'.



More information about the R-devel mailing list