Re: [R] R CMD check: no visible binding for global variable

From: Rolf Turner <rolf.turner_at_xtra.co.nz>
Date: Tue, 17 May 2011 11:16:20 +1200

On 17/05/11 06:05, swaraj basu wrote:
> Dear All,
> I have built a package which has a data.frame "annotIndex.rda
> in its "data" folder.
> I am using this data frame within two functions in my package.
>
> Though my package works fine, yet when I do a
> R CMD check
>
> to my package I get the following two notes
>
> get.affy.ensembl: no visible binding for global variable
> ‘annotIndex’
> get.affy.id: no visible binding for global variable
> ‘annotIndex’
>
> I need help in understanding these notes, and how can I avoid
> them.
This may be a case of the blind leading the blind, but here goes.

Understanding is simple (I think!). You are referring to an object "annotIndex"
inside a function, as in

foo <- function(x) {
x + annotIndex # Don't worry about the fact that this doesn't make sense! }

When the package checker looks at this it says "Hmmmm, annotIndex has never been defined (inside "foo") so it might not exist. There *could* be a problem here."

What to do about it: One solution is just to ignore the note; it's only a note,
not an error, nor even a warning, and you know that there isn't actually a problem.

The solution that is often suggested --- see

RSiteSearch("{no visible binding}",restrict=c("Rhelp02","Rhelp08"))

of assigning annotIndex a value, e.g. annotIndex <- NULL, at the beginning of your function doesn't work here since that local NULL value will over-ride the
global value that you really want.

You might try (the appropriate analogue of) x + get("annotIndex",envir=.GlobalEnv).

That should satisfy the package checker. (I haven't tested it, but.)

Dunno if this has an adverse impact on the efficiency of your code.

HTH cheers,

Rolf Turner



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Mon 16 May 2011 - 23:19:35 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 16 May 2011 - 23:40:07 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive