[Bioc-devel] importing a function that uses data()

Martin Morgan mtmorgan at fhcrc.org
Fri Aug 17 22:25:54 CEST 2012


On 08/17/2012 10:07 AM, Stephanie M. Gogarten wrote:
> In GWASTools, I import the paintCytobands function from quantsmooth:
> importFrom(quantsmooth, paintCytobands, lengthChromosome)
>
> The paintCytobands function loads a data set called chrom.bands:
> data(chrom.bands)
>
> In creating my package vignette, I now get the error:
> Warning in data(chrom.bands) : data set ‘chrom.bands’ not found
>
> Error: processing vignette ‘DataCleaning.Rnw’ failed with diagnostics:
>   chunk 100
> Error in subset(chrom.bands, chrom.bands$chr %in% chrom) :
>    object ‘chrom.bands’ not found
>
>
> I can fix this by including the quantsmooth package in "Depends" rather
> than "Imports," but I am wondering if there is a better way?

Hi Stephanie (and quantsmooth and other package maintainers) --

I looked in to this. I think quantsmooth should say

   data(chrom.bands, package="quantsmooth", envir=environment())

in paintCytobands (and elsewhere).

Although the documentation for ?data is a bit ambiguous, it says that if 
the 'package' argument is not specified then the data is looked for in 
packages on the search() path. But (a) an Import'ed package is not on 
the search path and (b) even if it were, its data set could be masked by 
some other package. So providing a 'package' argument seems like a best 
practice.

The default value for envir is .GlobalEnv, which means that the data is 
loaded to the global environment and in the process writes over any 
identically named variables that are already defined there. The 
environment() value is the environment of the function in which the call 
to data() is evaluated, so worst-case is that the author of the original 
function clobbers variables in their own function.

Martin



>
> thanks,
> Stephanie
>
> _______________________________________________
> Bioc-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/bioc-devel


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

Location: Arnold Building M1 B861
Phone: (206) 667-2793



More information about the Bioc-devel mailing list