Why does R function print.xtableFtable ignore my options?

怎甘沉沦 提交于 2019-12-24 10:20:06

问题


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?


回答1:


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!]
# ---
# ---


来源:https://stackoverflow.com/questions/40194390/why-does-r-function-print-xtableftable-ignore-my-options

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!