简体   繁体   English

无法从xtable R包获得正确的tex输出

[英]unable to get the right tex output from xtable R package

I have been unable to get a correct tex output with xtable R package: This is the R code in the chunk of a knitr document 我无法使用xtable R包获得正确的tex输出:这是编织文档中的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")

This is the corresponding output in tex files: 这是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}

The command that includes region & multicolumn ... is not seen the tex output. 包含region&multicolumn ...的命令未显示tex输出。 Is this due to me using xtableList? 这是我使用xtableList造成的吗?

I received an email to my question from xtable author David Scott: 我收到xtable作者David Scott提出的关于问题的电子邮件:

I am glad to see you are using xtableList. 我很高兴看到您正在使用xtableList。 It doesn't surprise me that add.to.row has problems though since xtableList uses add.to.row to provide intermediate headings (subheadings). 尽管xtableList使用add.to.row提供中间标题(子标题),但是add.to.row出现问题并不令我感到惊讶。

So I was able to work around this by following his suggestion: use as.is for the Sweave/knitr chunk and use string replacement to insert the string at rowcom$command. 因此,我可以按照他的建议解决此问题:将as.is用于Sweave / knitr块,并使用字符串替换在rowcom $ command处插入字符串。 So some arguments of print.xtableList are used internally in the function and should not be used. 因此,print.xtableList的某些参数在函数内部使用,不应使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM