【问题标题】:unable to get the right tex output from xtable R package无法从 xtable R 包中获得正确的 tex 输出
【发布时间】:2017-03-14 04:24:53
【问题描述】:

我无法使用 xtable R 包获得正确的 tex 输出: 这是 knitr 文档块中的 R 代码

  attr(p_val_table_list, "subheadings") <- paste0("Hemisphere : ",c("Left","Right"))
   xtablelist <- xtableList(p_val_table_list)
   col.names <- c("KS test","MWU test", "Welch's t-test")
  rowcom <- list(pos = c(4), 
     command = paste0(c("Region",paste0(" & \\multicolumn{3}{c}{", col.names , '}', collapse='')), '\\\\'))
  #print(addtorow)
  print(xtablelist, add.to.row = rowcom, only.contents=FALSE,
    include.rownames=TRUE, sanitize.colnames.function = simp.colnames,
    type="latex",floating.environment = "sidewaystable")

这是tex文件中对应的输出:

% latex table generated in R 3.2.3 by xtable 1.8-2 package
% Mon Oct 31 21:55:14 2016
\begin{sidewaystable}[ht]
\centering
\begin{tabular}{rlllllllll}
  \hline
 & two.sided & less & greater & two.sided & less & greater & two.sided & less & greater \\ 
  \hline
\multicolumn{9}{l}{Hemisphere : Left}\\
normal vs aMCI & $<$0.0001 & 0.2541 & $<$0.0001 & $<$0.0001 & $<$0.0001 & 1 & $<$0.0001 & $<$0.0001 & 1 \\ 
  normal vs amdMCI & $<$0.0001 & 0.8165 & $<$0.0001 & $<$0.0001 & $<$0.0001 & 1 & $<$0.0001 & $<$0.0001 & 1 \\ 
  normal vs nMCI & $<$0.0001 & 0.8951 & $<$0.0001 & $<$0.0001 & $<$0.0001 & 1 & $<$0.0001 & $<$0.0001 & 1 \\ 
  normal vs nmdMCI & $<$0.0001 & $<$0.0001 & 0.1294 & $<$0.0001 & 1 & $<$0.0001 & $<$0.0001 & 1 & $<$0.0001 \\ 
  aMCI vs amdMCI & $<$0.0001 & 0.8959 & $<$0.0001 & $<$0.0001 & $<$0.0001 & 1 & $<$0.0001 & $<$0.0001 & 1 \\ 
  aMCI vs nMCI & $<$0.0001 & 0.252 & $<$0.0001 & $<$0.0001 & $<$0.0001 & 1 & $<$0.0001 & $<$0.0001 & 1 \\ 
  nMCI vs nmdMCI & $<$0.0001 & $<$0.0001 & 0.7627 & $<$0.0001 & 1 & $<$0.0001 & $<$0.0001 & 1 & $<$0.0001 \\ 
   \hline
\multicolumn{9}{l}{Hemisphere : Right}\\
normal vs aMCI1 & $<$0.0001 & 0.2541 & $<$0.0001 & $<$0.0001 & $<$0.0001 & 1 & $<$0.0001 & $<$0.0001 & 1 \\ 
  normal vs amdMCI1 & $<$0.0001 & 0.8165 & $<$0.0001 & $<$0.0001 & $<$0.0001 & 1 & $<$0.0001 & $<$0.0001 & 1 \\ 
  normal vs nMCI1 & $<$0.0001 & 0.8951 & $<$0.0001 & $<$0.0001 & $<$0.0001 & 1 & $<$0.0001 & $<$0.0001 & 1 \\ 
  normal vs nmdMCI1 & $<$0.0001 & $<$0.0001 & 0.1294 & $<$0.0001 & 1 & $<$0.0001 & $<$0.0001 & 1 & $<$0.0001 \\ 
  aMCI vs amdMCI1 & $<$0.0001 & 0.8959 & $<$0.0001 & $<$0.0001 & $<$0.0001 & 1 & $<$0.0001 & $<$0.0001 & 1 \\ 
  aMCI vs nMCI1 & $<$0.0001 & 0.252 & $<$0.0001 & $<$0.0001 & $<$0.0001 & 1 & $<$0.0001 & $<$0.0001 & 1 \\ 
  nMCI vs nmdMCI1 & $<$0.0001 & $<$0.0001 & 0.7627 & $<$0.0001 & 1 & $<$0.0001 & $<$0.0001 & 1 & $<$0.0001 \\ 
   \hline
\multicolumn{9}{l}{}\\
\end{tabular}
\end{sidewaystable}

包含 region & multicolumn ... 的命令在 tex 输出中看不到。 这是因为我使用了 xtableList 吗?

【问题讨论】:

    标签: r latex knitr xtable


    【解决方案1】:

    我收到了一封来自 xtable 作者 David Scott 的电子邮件:

    很高兴看到您正在使用 xtableList。这并不让我感到惊讶 add.to.row 有问题,因为 xtableList 使用 add.to.row 提供中间标题(副标题)。

    所以我能够按照他的建议解决这个问题: 将 as.is 用于 Sweave/knitr 块并使用字符串替换在 rowcom$command 处插入字符串。 所以 print.xtableList 的一些参数是在函数内部使用的,不应该使用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-09
      • 2011-12-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多