[Rd] another import puzzle
Ben Bolker
bbolker at gmail.com
Sat Mar 26 19:14:12 CET 2011
Dear list,
I have another (again possibly boneheaded) puzzle about importing,
again encapsulated in a nearly trivial package. (The package is posted
at <http://www.math.mcmaster.ca/bolker/misc/coefsumtest_0.001.tar.gz>.)
The package consists (only) of the following S3 method definitions:
coeftab <- function(object, ...) UseMethod("coeftab",object)
coeftab.default <- function(object,...) {
print(class(summary(object)))
coef(summary(object))
}
The NAMESPACE tries to pull in the necessary bits and pieces from lme4
to extract summaries and coefficients:
export("coeftab","coeftab.default")
importClassesFrom(lme4,"mer","summary.mer")
importMethodsFrom(lme4,"coef","summary","show","print")
exportMethods("coef","summary","show","print")
exportClasses("mer","summary.mer")
S3method(coeftab,default)
The package passes the routine parts of R CMD check. The following
test shows that, with lme4 loaded, coef(summary([object of class
"mer"])) works in the global environment, but not in a function defined
inside the namespace of the package.
The output ends with:
> coeftab.default(gm1)
[1] "summaryDefault" "table"
Error in object$coefficients : $ operator is invalid for atomic vectors
Calls: coeftab.default -> coef -> coef -> coef.default
which indicates that inside the function, summary() is calling
summary.default instead of seeing the summary method for "mer" objects ...
I have (re-re-re-)read the appropriate R-exts section, without luck,
and tried various minor variations (e.g. import()ing all of lme4,
changing the order of the directive, ...).
Help ... ?
sincerely
Ben Bolker
=====
test.R
=====
library(coefsumtest)
library(lme4)
gm1 <- glmer(cbind(incidence, size - incidence) ~ period + (1 | herd),
family = binomial, data = cbpp)
coef(summary(gm1)) ## works
f <- function(g) {
coef(summary(g))
}
f(gm1) ## works
coeftab.default(gm1) ##
More information about the R-devel
mailing list