Friday, January 30, 2009

Importing Generic Function from Other Package: A Tip on Writing a R Package

I did not know this and had to spend the whole week to figure out what's wrong with my code.

I was updating the mi package. While I was doing code checking procedure, I always got a error message that I did not know what was going on. I remember last time when I encountered this, I just reduced the package dependency or simply don't use the S4 language. Anyway, here is the problem:

mi is dependent on arm. And arm is dependent on Matrix and lme4. There are new methods in
mi for function like coef, resid, fitted and update. And these functions are exported from stats package. But Matrix and lme4 also export the same functions. So R complains with the error message.

The solution is: instead of importing these functions from stats package as suggested by the R check, we should really import them from Matrix and lme4 even though mi is indirectly dependent on those packages.


Antonio Pedro said...


Does it work for MAC?

Many thanks,


Yu-Sung Su said...

Yes, I believe so.