[R-pkg-devel] Extending an S3 method, but putting the package in Suggests?
David Hugh-Jones
davidhughjones at gmail.com
Tue Mar 14 10:26:49 CET 2017
Just out of interest, what would happen if I used the hacky solution of
simply exporting my own method like:
as.FlexTable <- function(x, ...) UseMethod("as.FlexTable")
I am fairly sure you will tell me that fire and brimstone will rain down…
But it sure seems simple compared to writing another package and getting
it on CRAN...
David
On Tue, 14 Mar 2017 at 09:06, Martin Maechler <maechler at stat.math.ethz.ch>
wrote:
> >>>>> David Hugh-Jones <davidhughjones at gmail.com>
> >>>>> on Tue, 14 Mar 2017 02:46:35 +0000 writes:
> >>>>> David Hugh-Jones <davidhughjones at gmail.com>
> >>>>> on Tue, 14 Mar 2017 02:46:35 +0000 writes:
>
> > Hi,
> > Cross-posted from SO:
> >
> http://stackoverflow.com/questions/42776058/extending-an-s3-generic-from-an-optional-package
>
> ((sent my answer there as well))
>
> > I have a package which provides an as.FlexTable method for its
> objects,
> > extending the S3 generic from the ReporteRs package. So, my
> NAMESPACE file,
> > generated by roxygen, has lines:
>
> > importFrom(ReporteRs,as.FlexTable)
> > ...
> > S3method(as.FlexTable,huxtable)
> > ...
> > export(as.FlexTable)
>
> > I don't much want to put ReporteRs in Imports: in the DESCRIPTION
> file,
> > because it involves a big external dependency on Java. But, when I
> put it
> > into Suggests:, R CMD check gives me errors like "Namespace
> dependency not
> > required".
>
> > Is there anyway I can extend the generic without making a hard
> dependency?
>
> No. Importing is a hard dependency..
> Some people do not import formally but use '<pkgNamespace>::<obj>'
> instead, *and* conditionalize their code on the availability of
> that namespace.
> I don't recommend that at all, and particularly not for
> extending a generic.
>
> I recommend you talk with the maintainer of 'ReporteRs':
> 1) You could use a common (yet-to-create) very small package say
> 'flexS3generics'
> which provides S3 generics (and S4 if ..) you want to use
> both, and then both you and her/him import from that mini package.
> You'd be both authors of that package.
>
> 2) If your package is much smaller (in its footprint, incl
> dependencies) than 'ReporteRs' she/he may agree to import the
> S3 generic from your package instead of the other way around.
>
> Both are clean solutions,
> and both need some time-coordination when releasing to CRAN,
> '1)' being easier: Once the 'flexS3generics' is released to
> CRAN, change (both) your package(s) to
> importFrom(flexS3generics,*) but these changes and CRAN
> submissions are then independent of each other.
>
>
> > Cheers,
> > David
>
> --
Sent from Gmail Mobile
[[alternative HTML version deleted]]
More information about the R-package-devel
mailing list