[Roxygen-devel] S4 implementation of @usage

Hadley Wickham hadley at rice.edu
Wed Aug 29 16:07:41 CEST 2012


Hi Vitalie,

It would also be really useful if you could sketch out the S4 design
to work with a tag like usage.

Would you need multiple dispatch so that usage looks like:

setMethod("ProcessTag", signature(tag = "RoccerUsage", object =
"function"), ...)
setMethod("ProcessTag", signature(tag = "RoccerUsage", object =
"classRepresentation"), ...)
setMethod("ProcessTag", signature(tag = "RoccerUsage", object =
"MethodDefinition"), ...)

Is that better than this? (effectively the same as the current s3
implementation)

setMethod("ProccessTag", signature(tag = "RoccerUsage"), function(tag, obj) {
  makeUsageObject(obj at value, obj at name)
}
setMethod("makeUsageObject", signature(object = "function"), ...)
setMethod("makeUsageObject", signature(object = "classRepresentation"), ...)
setMethod("makeUsageObject", signature(object = "MethodDefinition"), ...)


Currently the roccer implements the strategy design pattern so that
you can separately specify the parser and the output. How would you do
the same with S4?  Multiple inheritance?

setClass("RoccerUsage", contains = c("RoccerParseSingle", "RoccerOutRd"))
setMethod("ProcessTag", signature(tag = "RoccerUsage"), function(tag, roc) ...)
setMethod("OutRd", signature(tag = "RoccerUsage"), function(tag) ...)

or would you do that inside the methods?

setClass("RoccerUsage", contains = "Roccer")
setMethod("Process", signature(tag = "RoccerUsage"), function(tag,
rocblocks) ...)
setMethod("Output", signature(tag = "RoccerUsage"), function(tag,
rocblocks) ...)

?

Hadley



-- 
Assistant Professor
Department of Statistics / Rice University
http://had.co.nz/


More information about the Roxygen-devel mailing list