[R-pkg-devel] How to make S3-method for the "format" generic for class inheriting from "AsIs"
erik.bulow at rccvast.se
Tue Dec 8 12:13:31 CET 2015
I am one of two authors to the package "sweidnumbr"
package introduce an S3-class called "pin" and methods etc for handling
personal identification numbers.
An object might look like:
x <- structure("1912121212", class = c("AsIs", "pin", "character"))
We want the "AsIs" class to allow for example recycling when the object is
put into a data.frame. Problem is that we would also like to have our own
format.pin-method. This is problematic since base::format.AsIs does not
use "NextMethod" (which all other xxx.AsIs methods do).
We can think of two possible solutions:
1. We can redefine the format-function to handle this but will then get a
check note for masking base::format.
2. We could skip the format.pin method and introduce a stand alone
function called "pin_format" or similair (but our method is very similair
to base::format.Date and we would like to benefit from that).
We can not skip the "AsIs" class inheritence. If we do, we need to rewrite
"data.frame" (which is a function and not an S3 generic in opposite to
as.data.frame for which we could just add as.data.frame.pin). If we do, we
still get the same check note as above but for masking base::data.frame
Is it possible to use both the benefits of the AsIs-class but to also
define our own format-method without masking anything from other packages?
More information about the R-package-devel