I do not seem to fully understand how to add a method to a generic function from another package, in an R package that I am currently developing.
I am now trying to make a method autoplot.myobj
for the autoplot
generic defined in ggplot2
, without adding ggplot2
to DEPENDS.
For this line in NAMESPACE: S3method(autoplot,emfrail)
, R CMD build fails with
Error: autoplot not found whilst loading namespace
Then, If I also add importFrom(ggplot2, autoplot)
, R CMD build works, but R CMD check returns
Error: could not find function autoplot
So I understand that a generic imported from another package must also be exported. Then, if I also add export(autoplot)
, R CMD build works, R CMD check gives
Warning: undocumented code objects
This means that I also have to document autoplot
, although it is already documented in ggplot2
. Then I followed the advice here and I also have in the NAMESPACE export(autoplot.emfrail)
in addition to all the previous ones.
Then I added an @rdname autoplot.emfrail
roxygen tag to the documentation. Then R CMD build and R CMD check work both. The disadvantage that I see is that with ?autoplot
now, the function is documented in both ggplot2
and my package.
Is this the best way to make an S3 method for a generic from another package?