[Rd] no visible binding for global variable for data sets in a package
peter dalgaard
pdalgd at gmail.com
Wed Aug 27 16:41:33 CEST 2014
Using data() in a package with lazyloaded data seems like asking for trouble to me. But you're making me curious (and I'm too lazy[*] to set up for rebuilding the package myself):
Did you actually try putting battingLabels & friends in the namespace? What happened?
A workaround could be to use rbind(Lahman::battingLabels,....) which runs a bit against the grain for me.
I think the right answer _is_ to export the lazy data; the question is how to do it. There's nothing particularly strange about exporting non-functions ("letters" would be an example, save for the special status of package:base). If you attach the package, the lazyloaded data appear in the same environment as the exported function so they are de facto already in the namespace for the purposes of library() and `::`. So I agree, something like exportData() would be useful. (Or some other mechanism. You might want to be able to export data selectively.)
- pd
[*] "Burdened with pressing obligations", if you like.
On 27 Aug 2014, at 16:07 , Michael Friendly <friendly at yorku.ca> wrote:
> 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'.
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
--
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd.mes at cbs.dk Priv: PDalgd at gmail.com
More information about the R-devel
mailing list