[R] nice report generator?

Duncan Murdoch murdoch.duncan at gmail.com
Mon Jan 30 15:09:13 CET 2012


On 30/01/2012 6:59 AM, Tal Galili wrote:
> Helloe dear Duncan, Gabor, Michael and others,
>
> After taking some time, I wrote a bridge function between a "cast_df"
> object from the {reshape} package into a table in Duncan's new {tables}
> package.
>
> The motivation was to make "cast_df" table prettier in the R terminal, as
> well as allow us to export a pretty version of the table to latex (using
> Hmisc::latex, on the output of tabular.cast_df)
>
> The code is now available on:
> http://www.r-statistics.com/2012/01/printing-nested-tables-in-r-bridging-between-the-reshape-and-tables-packages/
>
> I would be happy for any input/revisions/suggestions from you.

Seems like a nice idea.  Two comments:

1. I did add a Factor() function as described in the message you quote 
from me, so you might be able to use that and simplify things a little.

2. It's more flexible to construct the language object as a language 
object, rather than pasting something together and parsing it.  For one 
thing, that allows non-syntactic variable names; I think it's also 
easier to read.  So your code

txt<- paste("tabular(value*v*", LEFT , "~" ,RIGHT ,", data = m_xx, suppressLabels  = 2,...)", sep = "")
eval(parse(text = txt ))

could be rewritten as

formula<- substitute( value*v*LEFT ~ RIGHT, list(LEFT=LEFT, RIGHT=RIGHT))
tabular(formula, data = m_xx, suppressLabels = 2, ...)

It might make sense to put something like this into the tables package, but I don't want to have a dependency on reshape.

Duncan Murdoch



More information about the R-help mailing list