From friendly at yorku.ca  Wed Aug 27 16:07:04 2014
From: friendly at yorku.ca (Michael Friendly)
Date: Wed, 27 Aug 2014 10:07:04 -0400
Subject: [Rd] no visible binding for global variable for data sets in a
	package
In-Reply-To: <53FDDD55.1040807@yorku.ca>
References: <53FD030A.1020709@yorku.ca>	<21501.41940.216907.982935@stat.math.ethz.ch>
	<53FDDD55.1040807@yorku.ca>
Message-ID: <53FDE608.40801@yorku.ca>

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'.



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