[R] Parametrizing heading in tables package

Duncan Murdoch murdoch.duncan at gmail.com
Wed Nov 20 15:35:41 CET 2013


On 20/11/2013 9:17 AM, Jean-Louis Abitbol wrote:
> Dear R-Helpers,
>
> I am using the (great) tables package in a function this way:
>
> parplot <- function (x){
> test <- pkqps[pkqps$estimate == x,]
> ####
> #some plotting
> #####
> tab <- tabular((Heading("Analyte")*(analyte) * Heading(Site)* (fsite))
>           ~ (n=1)+ Justify(c)*Heading(substitute(test$estimate[1]))
>                 *(result)*(Mean + Median + Min + Max + CV)
>                     * Format(digits = 1), data = test)
> html(tab, file = paste(qpar$param[1],"stat",".html", sep=""))
> }
> parplot("Cmax")
> parplot("AUClast")
> etc...
>
> I am trying to parametrize the heading in tabular with
> "Heading(substitute(test$estimate[1]))".
> test$estimate[1] is a character variate which is the name I want to
> appear in the heading (ie Cmax for example in the first call of the
> function.
>
> This does not work and produces just "substitute(test$estimate[1])" in
> the heading.

I would use substitute() on the whole formula.  For example,

a <- "New heading"
x <- rnorm(100)

tabular( substitute( Heading( head )*x ~ mean, list(head = a) ) )

Duncan Murdoch



More information about the R-help mailing list