Martin Morgan
2011-Dec-15 23:34 UTC
[Rd] S4 NAMESPACE method imports and exports do not include (promoted?) generics
In
> R.version.string
[1] "R Under development (unstable) (2011-12-15 r57901)"
section 1.6.6 of 'Writing R Extensions' says
Note that exporting methods on a generic in the namespace will
also export the generic, and exporting a generic in the
namespace will also export its methods.
and
Note that importMethodsFrom will also import any generics defined in
the namespace on those methods
However, if PkgA promotes 'unique' to a generic and exports that
DESCRIPTION:
Imports: methods
R/f.R:
setGeneric("unique")
NAMESPACE:
export(unique)
and PkgB creates and exports a method on unique
DESCRIPTION
Imports: methods, PkgA
R/f.R:
setClass("B", representation(b="numeric"))
setMethod(unique, "B",
function(x, incomparables=FALSE, ...) unique(x at b))
NAMESPACE:
importFrom(PkgA, unique)
exportClasses(B)
exportMethods(unique)
and PkgC wants to import PkgB's classes and methods
DESCRIPTION
Imports: methods, PkgB
R/f.R
cunique <- function(x) unique(x)
NAMESPACE
importMethodsFrom(PkgB, unique)
export(cunique)
then
(a) the 'unique' generic is not available to the user of PkgB
> library(PkgB)
> unique(new("B", b=1:5))
Error in unique.default(new("B", b = 1:5)) :
unique() applies only to vectors
and (b) the generic has not been imported to PkgC's namespace
> cunique(new("B", b=1:5))
Error in unique.default(b) : unique() applies only to vectors
A workaround is for PkgB to also export(unique), and for PkgC to also
importFrom(PkgA, unique), but is this the intention?
This is arising from Bioconductor efforts to place commonly promoted
functions and S3 classes into a single package, to avoid conflicts when
the same function is promoted independently by several packages.
Martin
--
Computational Biology
Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N. PO Box 19024 Seattle, WA 98109
Location: M1-B861
Telephone: 206 667-2793
Martin Morgan
2011-Dec-16 14:16 UTC
[Rd] S4 NAMESPACE method imports and exports do not include (promoted?) generics
tar of Pkgs A, B, C attached. Martin On 12/15/2011 03:34 PM, Martin Morgan wrote:> In > > > R.version.string > [1] "R Under development (unstable) (2011-12-15 r57901)" > > section 1.6.6 of 'Writing R Extensions' says > > Note that exporting methods on a generic in the namespace will > also export the generic, and exporting a generic in the > namespace will also export its methods. > > and > > Note that importMethodsFrom will also import any generics defined in > the namespace on those methods > > However, if PkgA promotes 'unique' to a generic and exports that > > DESCRIPTION: > Imports: methods > > R/f.R: > setGeneric("unique") > > NAMESPACE: > export(unique) > > and PkgB creates and exports a method on unique > > DESCRIPTION > Imports: methods, PkgA > > R/f.R: > setClass("B", representation(b="numeric")) > setMethod(unique, "B", > function(x, incomparables=FALSE, ...) unique(x at b)) > > NAMESPACE: > importFrom(PkgA, unique) > exportClasses(B) > exportMethods(unique) > > and PkgC wants to import PkgB's classes and methods > > DESCRIPTION > Imports: methods, PkgB > > R/f.R > cunique <- function(x) unique(x) > > NAMESPACE > importMethodsFrom(PkgB, unique) > export(cunique) > > then > > (a) the 'unique' generic is not available to the user of PkgB > > > library(PkgB) > > unique(new("B", b=1:5)) > Error in unique.default(new("B", b = 1:5)) : > unique() applies only to vectors > > and (b) the generic has not been imported to PkgC's namespace > > > cunique(new("B", b=1:5)) > Error in unique.default(b) : unique() applies only to vectors > > A workaround is for PkgB to also export(unique), and for PkgC to also > importFrom(PkgA, unique), but is this the intention? > > This is arising from Bioconductor efforts to place commonly promoted > functions and S3 classes into a single package, to avoid conflicts when > the same function is promoted independently by several packages. > > Martin-- Computational Biology Fred Hutchinson Cancer Research Center 1100 Fairview Ave. N. PO Box 19024 Seattle, WA 98109 Location: M1-B861 Telephone: 206 667-2793 -------------- next part -------------- A non-text attachment was scrubbed... Name: PkgABC.tar Type: application/x-tar Size: 2270 bytes Desc: not available URL: <https://stat.ethz.ch/pipermail/r-devel/attachments/20111216/4803470d/attachment.tar>
Maybe Matching Threads
- "False" warning on "replacing previous import" when re-exporting identical object
- Using requireNamespace() instead of require()
- Are downstream dependencies rebuilt when a package is updated on CRAN?
- S4 Generics and NAMESPACE : justified warning ?
- namespace S3 and S4 generic imports cannot both be satisfied: