[R] Some problems with latex(ftable)

Frank E Harrell Jr f.harrell at vanderbilt.edu
Sun Jul 16 07:41:21 CEST 2006


Richard M. Heiberger wrote:
> The ftable structure is not an ordinary matrix.  Instead, it has the
> body of the table with several cbind- and rbind-ed rows and columns of
> label information.  The example in ?ftable has two row factors and two
> column factors.
> 
> Continuing with the example in ?ftable, enter
> 
> 
> tmp <- ftable(mtcars$cyl, mtcars$vs, mtcars$am, mtcars$gear, row.vars = c(2, 4), 
>               dnn = c("Cylinders", "V/S", "Transmission", "Gears"))
> 
> print.default(tmp)
> 
> To get what you are looking for, you will need to intercept write.ftable
> with, for example,
> 
> trace(write.ftable, exit=recover)
> 
> then do 
> 
> 3
> tmp.latex <- latex(t(x))
> print.default(tmp.latex)
> 
> Now open up t.latex and prepend
> \documentstyle{article}
> \begin{document}
> 
> and append
> \end{document}
> 
> then latex it.
> 
> This gets you close to what you want and you can work with the generated
> t.tex file to get the rest of the detail.  Or you can work with the
> numerous arguments we built into latex (see ?latex) to get some of them
> automatically generated.
> 
> tmp2.latex <- latex(t(x), col.just=rep(c("l","r"), c(3,6)),
>                     n.rgroup=c(3,6), file="t2.tex")
> 
> 
> Now open up t2.latex and pre- and append the latex controls to it.
> 
> 
> This works well for one or two examples.  To do many, then you will
> need to follow Frank's suggestion and build all of this into a method.
> Once the method works well, send it to Frank and he will consider
> including it in the next release (Frank, I hope that's a fair offer I
> make for you to do).

Yes, working with Charles Thomas Dupont we'll be glad to add such a 
contribution to latex.  Thanks for your excellent ideas above Rich.

-Frank

> 
> 
> This raises a question from me to the R developers.  I would have
> written write.ftable to return t(x), not ox.  print is constrained to
> return its argument.  I thought write had more freedom.  Then I would
> respecify
> 
> print.ftable <- function (x, digits = getOption("digits"), ...) {
>      write.ftable(x, quote = FALSE, digits = digits)
>      invisible(x)
> }
> 
> Had this been done then the current task would simplify to
> 
> latex(write(tmp))
> 
> Te question is: why was write.ftable designed to follow the
> print.ftable constraint on returned value.
> 
> ps. I just designed the method.  Take write.ftable, drop the last line
> and give it a new name.  then you can latex the output of that new
> function.
> 
> Rich
>



More information about the R-help mailing list