In principle, I could keep these extensions not-exported, and this would also allow me to not-add redundant documentation for these already well-documented methods, while still also passing R CMD check myPackage
without any reported WARNING
s.
What are some of the drawbacks, if any? Is this possibly recommended to keep extensions of basic methods compartmentalized within the package that defines them? Alternatively, will this make it more difficult for another package to depend on mine, if certain core method-extensions are not exported?
For example, if I don't document and don't export the following:
setMethod("show", "myPackageSpecialClass", function(object){ show(NA) })
I'm trying to flesh-out some of these finer details of best-practices with namespaces and base method extensions.
If you don't export the methods, then users (either at the command line or trying to use your classes and methods in their own package via imports) won't be able to use them -- your class will be displayed with the
show,ANY-method
.You are not documenting the generic
show
, but rather the method appropriate for your class,show,myPackageSpecialClass-method
. If in your NAMESPACE you(note that there is no way to export just some methods on the generic show) and provide no documentation,
R CMD check
will complainYour example (I know it was not meant to be a serious show method :) ) is a good illustration for why methods might be documented -- explaining to the user why every time they try and display the object they get
NA
, when they were expecting some kind of description about the object.One approach to documentation is to group methods with the class into a single Rd file,
myPackageSpecialClass-class.Rd
. This file would contain an aliasand a Usage
This works so long as no fancy multiple dispatch is used, i.e., it is clear to which class a method applies. If the user asks for help with
?show
, they are always pointed toward the methods package help page. For help on your methods / class, they'd need to ask for that specific type of help. There are several ways of doing this but my favorite isThis will not be intuitive to the average user; the (class|method) ? ... formulation is not widely used, and the specification of "generic,signature" requires a lot of understanding about how S4 works, including probably a visit to
selectMethod(show, "myPackageSpecialClass")
(because the method might be implemented on a class that myPackageSpecialClass inherits from) orshowMethods(class="myPackageSpecialClass", where=getNamespace("myPackage"))
(because you're wondering what you can do with myPackageSpecialClass).