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

Tarca, Adi atarca at med.wayne.edu
Tue Oct 28 17:05:46 CET 2008

Hi Martin,
This solved the issue. The code you provided works fine if the
data(dataset) call brings up only one variable called dataset also as
well but can be easy generalized.


-----Original Message-----
From: Martin Morgan [mailto:mtmorgan at fhcrc.org] 
Sent: Monday, October 27, 2008 5:59 PM
To: Tarca, Adi
Cc: bioconductor at stat.math.ethz.ch
Subject: Re: [BioC] Making data visible in packages (no visible binding
for global variable ...)

"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

.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