[BioC] Making data visible in packages (no visible binding for global variable ...)

Martin Morgan mtmorgan at fhcrc.org
Mon Oct 27 22:58:41 CET 2008

"Tarca, Adi" <atarca at med.wayne.edu> writes:

> Hi all,
> I am trying to write a package that contains one function MYF which
> requires some data (e.g. a matrix X).
> I put the matrix X in the \data folder as a myX.Rdata file. The function
> MYF makes a data(myX) call to make X available within MYF before doing
> some computations.
> The resulting package gets installed and runs fine but when I do the R
> CMD CHECK I get "no visible binding for global variable X".
> I have two questions:
> A) is there a better way to make X visible within MYF rather than making
> a data() call

data() loads the objects in the data file into the global (user)
environment, which might not be very polite (e.g., overwriting an
existing user object).

One option is to create a place for your data to be loaded, e.g.,
within the function where it will be used, or in your package name
space if it will be used repeatedly or if you wish users to access it
directly. For instance you might write (this is untested, so hopefully
not too misleading)

.myDataEnv <- new.env(parent=emptyenv()) # not exported

isLoaded <- function(dataset) {
   exists(dataset, .myDataEnv)

getData <- function(dataset) {
   if (!isLoaded(dataset))
     data(dataset, envir=.myDataEnv)


> B) wht should be done to fix the "no visible binding for global
> variable".
> Thanks,
> Adi Tarca
> _______________________________________________
> Bioconductor mailing list
> Bioconductor at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/bioconductor
> Search the archives: http://news.gmane.org/gmane.science.biology.informatics.conductor

Martin Morgan
Computational Biology / Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N.
PO Box 19024 Seattle, WA 98109

Location: Arnold Building M2 B169
Phone: (206) 667-2793

More information about the Bioconductor mailing list