桌子没有在Rmd笔记本内编织和打印?

问题描述 投票:2回答:1

我试图在我的Rmd笔记本中预览一个表而不编织整个文档。我打电话的时候:

xtable(anthro_table_f)

我明白了:

% latex table generated in R 3.5.1 by xtable 1.8-3 package
% Sun Sep 16 16:10:36 2018
\begin{table}[ht]
\centering
\begin{tabular}{rllll}
  \hline
 & Male & Female & p & test \\ 
  \hline
n & 708 & 219 &  &  \\ 
  HeightCm (mean (sd)) & 175.78 (7.10) & 163.65 (8.32) & $<$0.001 &  \\ 
  WeightKg (mean (sd)) & 78.11 (10.95) & 63.59 (8.86) & $<$0.001 &  \\ 
  BMI (mean (sd)) & 25.27 (3.19) & 23.80 (3.41) & $<$0.001 &  \\ 
  HI\_LateralityQuotient (mean (sd)) & 0.76 (0.43) & 0.87 (0.24) & 0.001 &  \\ 
  NeckLengthCm (mean (sd)) & 19.03 (2.98) & 17.39 (3.35) & $<$0.001 &  \\ 
  NeckCircCm (mean (sd)) & 38.29 (2.45) & 32.41 (2.05) & $<$0.001 &  \\ 
  HeadCircCm (mean (sd)) & 58.03 (1.84) & 56.28 (1.91) & $<$0.001 &  \\ 
  NeckVolumeCm (mean (sd)) & 2237.03 (483.68) & 1467.40 (363.38) & $<$0.001 &  \\ 
   \hline
\end{tabular}
\end{table} 

而不是代码下面的实际表。当我编织整个文档时,表格按预期显示。我如何获得实际的表格?

r r-markdown xtable
1个回答
1
投票

这里没有什么不对,你只需要了解它发生了什么。

(我将一般性地讨论编织文档时会发生什么。您的具体问题在我的答案底部得到解决。)

假设您创建了一个RMD文件,并希望将其编织为PDF。当您在RStudio中单击“编织”时,会发生一些事情。

  • 首先,运行R代码,代码和输出(取决于您的块选项)保存为TEX。该TEX还包括原始RMD文档的非R代码部分(例如,段落,部分等)。
  • 然后,pdfLatex(或luaLatex或您使用的任何Latex引擎)将该TEX文件转换为PDF文件。

这是图片中的过程:


1) You create an RMD file:

enter image description here


2) knitr "converts" your RMD document to a TEX document (Usually, you never see this part):

enter image description here


3) pdfLatex converts that TEX document to a PDF document:

enter image description here


最后,关于你的具体问题。 xtable的输出是为第二步(TEX文件)设计的。当您在RStudio中调用xtable(anthro_table_f)时,该表(以Latexy格式)将打印到R控制台。

© www.soinside.com 2019 - 2024. All rights reserved.