aL3xa/rapport — Issue #41: method based reporting
Author: jeroenooms
Created: 2012-02-27 23:36:26+00:00
State: open

Currently rapport() always assumes a dataframe, similar to e.g. `ggplot2`. It would be nice if there would also be functionality that uses method-based reporting, similar to R's `plot()` and `print()` methods. There are a lot of advantages to levering R's class/method system. It will be easier to use for the user, and allow package developers to create report templates for their custom objects based on the class of the object, in the same way as they might define summary(), print() and plot() methods for their objects.

I think it would not be too hard to introduce this. You would start with a generic method:

report <- function (data, template, template.package ...) {
UseMethod("report")
}

and define some basic reports for standard methods:

report.numeric <-function(data, template = default_numeric.tpl, template.package="rapport", digits = 5, align = "right", ...){
tpl <- system.file(template, package=template.package)
stopifnot(file.exists(tpl));
rapport(tpl, data=data, digits=digits, algin=align, ...);
}

You would define one or more, flexible templates standard templates for the standard R classes in e.g. report.data.frame. report.list, report.matrix, etc. This way the user can do:

report(cars);
report(cars, digits=10);
report(cars, template="numeric_alternate.tpl", customarg=TRUE);

Additionaly, this allows package developers to include reporting templates in their packages. Hence Douglas Bates could define a function like:

report.lmer <- function(data, template = multilevel.tpl', template.package="lme4", plotranef=TRUE, descriptives=TRUE, ...){
tpl <- system.file(template, package=template.package);
stopifnot(file.exists(tpl));
rapport(tpl, data=data, plotranef=plotranef, descriptives=descriptives ...);
}

So the advantage of this is not only that a user can do:

fm1 <- lmer(Reaction ~ Days + (Days|Subject), sleepstudy);
print(fm1);
report(fm1);

And get something nice 'out of the box'. Also they can easily check the required arguments for the report

args(report.lmer)