FarFarAway FarFarAway - 1 month ago 14
LaTeX Question

Why does R function print.xtableFtable ignore my options?

I am having the following code and print.xtableFtable ignores the additional options for latex.

##### Contingency tables - 34Y
library(xtable)
B <- ftable(prereg34Y_sub$employmentStatus34Y, prereg34Y_sub$ethnicity34Y, dnn=c("Unemployed", "NonBritish"))
sink("CTFemaleNonBrit34Y.tex", type="output")
print.xtableFtable(xtableFtable(B, method = "compact"), table.placement = "h!")
sink()


The output is:

% latex table generated in R 3.3.1 by xtable 1.8-2 package
% Sat Oct 22 18:08:35 2016
\begin{table}[ht]
\centering
\begin{tabular}{l |rr}
\hline
Unemployed $\vert$ NonBritish & \multicolumn{1}{l}{ 0} & \multicolumn{1}{l}{ 1} \\
\hline
0 & 2065 & 68 \\
1 & 31 & 2 \\
\hline
\end{tabular}
\end{table}


The position of the table is ht instead of h!. Does anyone have an idea why?

Answer

It doesn't seem that the table.placement argument gets passed along from print.xtableFtable to print.xtable, but you can set the optionally globally options(xtable.table.placement = "h!") before running print(xtableFtable(B))

Example

library(xtable)

# table.placement doesnt seem to work
B <- ftable(mtcars$am, mtcars$cyl, dnn=c("Unemployed", "NonBritish"))
print(xtableFtable(B), table.placement = "h!")     
# % latex table generated in R 3.3.1 by xtable 1.8-2 package
# % Sat Oct 22 18:00:52 2016
# \begin{table}[ht]
# ---
# ---

# But works for other data types
B2 <- table(mtcars$am, mtcars$cyl, dnn=c("Unemployed", "NonBritish"))
print(xtable(B2), table.placement = "h!")
# % latex table generated in R 3.3.1 by xtable 1.8-2 package
# % Sat Oct 22 18:00:52 2016
# \begin{table}[h!]
# ---
# ---  

So set options globally

options(xtable.table.placement = "h!")
print(xtableFtable(B))
# % latex table generated in R 3.3.1 by xtable 1.8-2 package
# % Sat Oct 22 18:00:52 2016
# \begin{table}[h!]
# ---
# ---
Comments