0

Hmisc::latex() seems to ignore all the arguments I give it, other than object. It's hard to point to a specific question I need answered, other than -- "How can I get Hmisc::latex()" to recognize the arguments its documentation says it should?

For example, these two commands produce the same output:

library(Hmisc)
library(tables)

t <- tabular(Species ~ (Sepal.Length + Sepal.Width)*(mean + sd), data = iris)

latex(object = t)
latex(object = t, booktabs = TRUE, align = rep('r', 5))

The output I get from both of these commands is:

\begin{tabular}{lcccc}
\hline
 & \multicolumn{2}{c}{Sepal.Length} & \multicolumn{2}{c}{Sepal.Width} \\ 
Species  & mean & sd & mean & \multicolumn{1}{c}{sd} \\ 
\hline
setosa  & $5.006$ & $0.3525$ & $3.428$ & $0.3791$ \\
versicolor  & $5.936$ & $0.5162$ & $2.770$ & $0.3138$ \\
virginica  & $6.588$ & $0.6359$ & $2.974$ & $0.3225$ \\
\hline 
\end{tabular}

I am using Hmisc 4.0-2 and tables 0.8 on R 3.2.2.

Edit: the caption and caption.loc arguments seem to be ignored as well. But if I run booktabs() prior to running latex(), that does take effect (changes the formatting of the table).

rcorty
  • 1,140
  • 1
  • 10
  • 28
  • I don't use this package, but I'm pretty satisfied with the `xtable` package in terms of formatting. Much of the formatting there is done with the `print.xtable` function, so perhaps there is a similar method with `Hmisc`. – lmo Jan 08 '17 at 21:27
  • I love `xtable`, but in this case I need to generate a table with a sort of 'nested' structure, so the formula options from `tabular` are a huge help. (I also need to make ~ 8 such tables and may need to re-make them a few times.) – rcorty Jan 08 '17 at 21:29

1 Answers1

1

@rcorty from two days ago -- you are misunderstanding what R does when you call latex() on your object of class tabular. You believe that it's running Hmisc::latex(), the default S3 method for the latex generic. But what's really happening is R is running tables::latex(), the S3 method for objects of class tabular, which is the class of the objects you have.

Have a look at the documentation for tables::latex() and you'll see what arguments you can use.

Though, it is a bit weird that you're not getting any error about unused arguments.

rcorty
  • 1,140
  • 1
  • 10
  • 28