Dear list, I have a problem with my NAMESPACE file. I need to import a package that does not define a name space, and I always get the same error on import(), specifying that the package I try to load 'does not have a name space'. Note that I also need to import a class from that package with importClassFrom() which seems to work. I tried different syntaxes like import(package), importFrom(package,variable), included .onLoad hook (as specified in R-ext) in the zzz.R file and also modified the Depends line in DESCRIPTION, which did not help. I am using the latest R 2.5.0 version. Am I missing something or is it not possible to import a package without name space? Thank you very much in advance, Laurent -- Laurent Gatto www.dnavision.be
[Bioc-devel] importing packages without a name space
7 messages · Laurent Gatto, Seth Falcon
Hi Laurent, "Laurent Gatto" <L.Gatto at dnavision.be> writes:
I have a problem with my NAMESPACE file. I need to import a package that does not define a name space, and I always get the same error on import(), specifying that the package I try to load 'does not have a name space'.
Actually, it is simply not possible to import from a package that does not have a name space of its own.
Note that I also need to import a class from that package with importClassFrom() which seems to work.
That is news to me; I would not expect it to work. I think the best you can do when you are using code from a package that does not have a NAMESPACE file is to put this package in the Depends field. The next thing to do is send a friendly email to the package's maintainer and ask that they add a name space to their package :-) + seth
Seth Falcon | Computational Biology | Fred Hutchinson Cancer Research Center http://bioconductor.org
2 days later
Hello again,
Thanks to Seth and Holger for their answers, but I still can not get it
working. I will provide more details.
I have to load two packages, geneplotter and simpleaffy and my package
(yaqcaffy) defines YAQCStats, a subclass of simpleaffy's QCStats class.
As geneplotter provides a name space, I load the required function with
'importFrom(geneplotter,smoothScatter)' in NAMESPACE. I also added
.onLoad <- function(lib,pkg) require(methods)
in R/zzz.R and geneplotter on the 'Imports' line in DESCRIPTION.
For simpleaffy, I do not import it in NAMESPACE, but add it as a
dependency in DESCRIPTION. Here is the .Fist.lib function as defined in
R/zzz.R:
.First.lib <- function(lib,pkg,where) {
require(simpleaffy,quietly=TRUE);
# Find what position in the search path this package is
where <- match(paste("package:", pkg, sep=""), search());
.initClassesAndMethods(where);
cacheMetaData(as.environment(where));
.createYAQCEnvironment()
}
When I check the src of my package (or try to load it), I get the
following error:
Error in setIs(Class, class2, classDef = classDef, where = where) :
Unable to find package environment for class "QCStats" to revise
subclass information
Error in setClass("YAQCStats", contains = "QCStats",
representation(average.noise = "numeric", :
error in contained classes ("QCStats") for class "YAQCStats";
class definition removed from "yaqcaffy"
In addition: Warning message:
Couldn't find superclass "QCStats" to clean up when removing subclass
references to class "YAQCStats" in: .removeSuperclassBackRefs(Class,
classDef, classWhere)
Error : unable to load R code in package 'yaqcaffy'
Error: package/namespace load failed for 'yaqcaffy'
Execution halted
If I add 'importClassesFrom(simpleaffy, QCStats)' in the NAMESPACE file,
I get
Error : package 'simpleaffy' does not have a name space
Error: package/namespace load failed for 'yaqcaffy'
Execution halted
Note that I get the same error message if I ask to import simpleaffy in
NAMESPACE.
Below is my sessionInfo() output after loading simpleaffy and
geneplotter.
Thank you very much in advance,
Laurent
--
Laurent Gatto
www.dnavision.be
sessionInfo()
R version 2.5.0 beta (2007-04-11 r41127)
i686-pc-linux-gnu
locale:
LC_CTYPE=en_US.UTF-8;LC_NUMERIC=C;LC_TIME=en_US.UTF-8;LC_COLLATE=en_US.U
TF-8;LC_MONETARY=en_US.UTF-8;LC_MESSAGES=en_US.UTF-8;LC_PAPER=en_US.UTF-
8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_US.UTF-8;LC_ID
ENTIFICATION=C
attached base packages:
[1] "splines" "tools" "stats" "graphics" "grDevices" "utils"
[7] "datasets" "methods" "base"
other attached packages:
geneplotter lattice annotate simpleaffy genefilter survival
"1.13.8" "0.15-3" "1.13.8" "2.9.3" "1.13.14" "2.31"
affy affyio Biobase
"1.13.19" "1.2.0" "1.13.49"
-----Original Message-----
From: Seth Falcon [mailto:sfalcon at fhcrc.org]
Sent: Friday, April 13, 2007 7:59 PM
To: Laurent Gatto
Cc: bioc-devel at stat.math.ethz.ch
Subject: Re: [Bioc-devel] importing packages without a name space
Hi Laurent,
"Laurent Gatto" <L.Gatto at dnavision.be> writes:
I have a problem with my NAMESPACE file. I need to import a package
that
does not define a name space, and I always get the same error on import(), specifying that the package I try to load 'does not have a name space'.
Actually, it is simply not possible to import from a package that does not have a name space of its own.
Note that I also need to import a class from that package with importClassFrom() which seems to work.
That is news to me; I would not expect it to work. I think the best you can do when you are using code from a package that does not have a NAMESPACE file is to put this package in the Depends field. The next thing to do is send a friendly email to the package's maintainer and ask that they add a name space to their package :-) + seth
Seth Falcon | Computational Biology | Fred Hutchinson Cancer Research Center http://bioconductor.org
"Laurent Gatto" <L.Gatto at dnavision.be> writes:
Hello again,
Thanks to Seth and Holger for their answers, but I still can not get it
working. I will provide more details.
I have to load two packages, geneplotter and simpleaffy and my package
(yaqcaffy) defines YAQCStats, a subclass of simpleaffy's QCStats class.
As geneplotter provides a name space, I load the required function with
'importFrom(geneplotter,smoothScatter)' in NAMESPACE. I also added
.onLoad <- function(lib,pkg) require(methods)
in R/zzz.R and geneplotter on the 'Imports' line in DESCRIPTION.
For simpleaffy, I do not import it in NAMESPACE, but add it as a
dependency in DESCRIPTION. Here is the .Fist.lib function as defined in
R/zzz.R:
.First.lib <- function(lib,pkg,where) {
require(simpleaffy,quietly=TRUE);
# Find what position in the search path this package is
where <- match(paste("package:", pkg, sep=""), search());
.initClassesAndMethods(where);
cacheMetaData(as.environment(where));
.createYAQCEnvironment()
}
If your package has a NAMESPACE file then the package initialization function that will be run is .onLoad and .First.lib will be ignored. So I'm pretty sure all of the code in .First.lib is not getting run. But are you sure you need all of that code anyhow? It looks to me like you have copy/pasted from another package (I'd like to know which one because perhaps it is not needed there either). There was a time long ago when S4 using packages needed such an arrangement, but in general they no longer do (there are a few cases, but I doubt your package is among them). So I'm guessing that .initClassesAndMethods() contains all of your setClass and setMethod calls. Can you try just putting those at the package level in your R code? What does .createYAQCEnvironment do? Have you exported all classes and methods in your NAMESPACE file? Perhaps you want to post your DESCRIPTION file as well, R is fairly picky about the syntax and I'd like to rule that out. + seth
Seth Falcon | Computational Biology | Fred Hutchinson Cancer Research Center http://bioconductor.org
Hello,
If your package has a NAMESPACE file then the package initialization function that will be run is .onLoad and .First.lib will be ignored. So I'm pretty sure all of the code in .First.lib is not getting run.
Yes indeed, I also tried to R CMD check the package without .Fist.Lib and it had no impact on the error message. I now moved .createYAQCEnvironment() in .onLoad.
But are you sure you need all of that code anyhow? It looks to me like you have copy/pasted from another package (I'd like to know which one because perhaps it is not needed there either). There was a time long ago when S4 using packages needed such an arrangement, but in general they no longer do (there are a few cases, but I doubt your package is among them).
You are right. I started to write the code using simpleaffy as an example, as it does similar things. Everything worked fine (and still does) without the NAMESPACE file.
So I'm guessing that .initClassesAndMethods() contains all of your setClass and setMethod calls. Can you try just putting those at the package level in your R code?
All the setClass and SetMethods are in the main R file.
What does .createYAQCEnvironment do?
The function creates a new environment and loads some data that is
stored in a file in the data directory of the package:
.createYAQCEnvironment <- function() {
if(!exists(".yaqcEnv")) {
.yaqcEnv <- new.env()
data(morespikes,envir =.yaqcEnv )
assign(".yaqcEnv",.yaqcEnv,envir=globalenv())
}
}
Have you exported all classes and methods in your NAMESPACE file?
Yes, I export the class with 'exportClasses("YAQCStats")', the formal
methods with exportMethods() and the other function with export().
Perhaps you want to post your DESCRIPTION file as well, R is fairly picky about the syntax and I'd like to rule that out.
Package: yaqcaffy
Title: Affymetrix expression data quality control and reproducibility
analysis
Version: 0.0.12
Author: Laurent Gatto
Description: Quality control of Affymetrix GeneChip expression data
and reproducibility analysis of human whole genome chips
with the MAQC reference datasets.
Maintainer: Laurent Gatto <l.gatto at dnavision.be>
Depends: R (>= 2.0), simpleaffy, methods
Imports: geneplotter
biocViews: Microarray,OneChannel,QualityControl
License: The Artistic License, Version 2.0
URL: http://www.bioconductor.org
Thank you,
Laurent
Laurent Gatto www.dnavision.be
"Laurent Gatto" <L.Gatto at dnavision.be> writes:
You are right. I started to write the code using simpleaffy as an example, as it does similar things. Everything worked fine (and still does) without the NAMESPACE file.
In general, that just isn't a good moel for how to do things. I am not surprised that you've encountered difficulties with using a NAMESPACE given that setup.
So I'm guessing that .initClassesAndMethods() contains all of your setClass and setMethod calls. Can you try just putting those at the package level in your R code?
All the setClass and SetMethods are in the main R file.
What does .createYAQCEnvironment do?
The function creates a new environment and loads some data that is
stored in a file in the data directory of the package:
.createYAQCEnvironment <- function() {
if(!exists(".yaqcEnv")) {
.yaqcEnv <- new.env()
data(morespikes,envir =.yaqcEnv )
assign(".yaqcEnv",.yaqcEnv,envir=globalenv())
}
}
It would be much cleaner to put this environment in your package name space and not muck with the globalenv. How about putting this in one of your .R files: .yaqcEnv <- new.env(parent=emptyenv(), hash=TRUE) data(morespikes, envir = .yaqcEnv) And then you can decide whether this is something the user should have access to by exporting this object in the NAMESPACE file or not.
Have you exported all classes and methods in your NAMESPACE file?
Yes, I export the class with 'exportClasses("YAQCStats")', the formal
methods with exportMethods() and the other function with export().
Good.
Perhaps you want to post your DESCRIPTION file as well, R is fairly picky about the syntax and I'd like to rule that out.
Package: yaqcaffy
Title: Affymetrix expression data quality control and reproducibility
analysis
Version: 0.0.12
Author: Laurent Gatto
Description: Quality control of Affymetrix GeneChip expression data
and reproducibility analysis of human whole genome chips
with the MAQC reference datasets.
Maintainer: Laurent Gatto <l.gatto at dnavision.be>
Depends: R (>= 2.0), simpleaffy, methods
Imports: geneplotter
biocViews: Microarray,OneChannel,QualityControl
License: The Artistic License, Version 2.0
URL: http://www.bioconductor.org
That looks reasonable. Are you still seeing the same error messages or are things working better/different now? + seth
Seth Falcon | Computational Biology | Fred Hutchinson Cancer Research Center http://bioconductor.org
An embedded and charset-unspecified text was scrubbed... Name: not available Url: https://stat.ethz.ch/pipermail/bioc-devel/attachments/20070417/7e26beba/attachment.pl