>>>> "MM" == Martin Maechler <[email protected]>
>>>> on Mon, 31 Aug 2009 14:51:16 +0200
MM> Yes, I agree, unjustified in your case.
MM> The question is: is there a patch which does differentiate
MM> between your situation and Martin's scenario -- or does your
MM> patch already do that?
Hi Martin,
Thanks for your response.
Here is an attempt to combine both views.
To check if the generic was derived from the function it wants to
overwrite, the following patch checks if the package associated with
the generic is the same as the one where the function was defined.
regards,
Yohan
Index: src/library/base/R/namespace.R
===================================================================
--- src/library/base/R/namespace.R (revision 49543)
+++ src/library/base/R/namespace.R (working copy)
@@ -797,8 +797,19 @@
}
}
for (n in impnames)
- if (exists(n, envir = impenv, inherits = FALSE))
- warning(msg, " ", n)
+ if (exists(n, envir = impenv, inherits = FALSE)) {
+ if (.isMethodsDispatchOn() && methods:::isGeneric(n, ns)) {
+ ## warning if generic overwrites a function which
+ ## it was not derived from
+ genNs <- methods:::slot(get(n, envir = ns), "package")
+ genImpenv <- environmentName(environment(get(n, envir =
impenv)))
+ genWarn1 <- (!identical(genNs, genImpenv))
+ ## warning if generic overwrites another generic
+ genWarn2 <- methods:::isGeneric(n, impenv)
+ if (genWarn1 || genWarn2)
+ warning(msg, " ", n)
+ } else warning(msg, " ", n)
+ }
importIntoEnv(impenv, impnames, ns, impvars)
if (register) {
addImports(self, ns,
______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel