[Rd] importing S3 methods with importFrom

Stephanie M. Gogarten sdmorris at u.washington.edu
Tue Jan 10 19:17:42 CET 2012


In my own package, I want to use the default S3 method of the generic 
function lrtest() from the lmtest package.  Since I need only one 
function from lmtest, I tried to use importFrom in my NAMESPACE:

importFrom(lmtest, lrtest)

However, this fails R CMD check in the examples:
Error in UseMethod("lrtest") :
   no applicable method for 'lrtest' applied to an object of class 
"c('glm', 'lm')"
Calls: assocTestRegression ... append -> RunRegression -> append -> 
unlist -> lrtest

Relevant line of code in assocTestRegression is
tmp <- append(tmp, unlist(lrtest(mod, mod0))[c(8,10)])
where mod and mod0 are both results of the glm() function.

If I instead import the entire package in my NAMESPACE:

import(lmtest)

The example runs without error.  Is there a way to import all methods 
for an S3 generic function without importing the entire package?

thanks,
Stephanie Gogarten

sessionInfo()
R version 2.14.0 (2011-10-31)
Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] lmtest_0.9-28 zoo_1.7-4

loaded via a namespace (and not attached):
[1] grid_2.14.0    lattice_0.20-0 tools_2.14.0



More information about the R-devel mailing list