2

I am trying to preview a table within my Rmd notebook without knitting the whole document. When I call:

xtable(anthro_table_f)

I get:

% 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} 

instead of the actual table below the code. When I knit the whole document, the table appears as expected. How do I get the actual table?

Hank Lin
  • 5,959
  • 2
  • 10
  • 17

1 Answers1

1

Nothing is incorrect here, you just need to understand what it happening.

(I'll discuss generally what happens when you knit a document. Your specific question is addressed at the bottom of my answer.)

Let's say you create an RMD file and you want to knit it to PDF. When you click "knit" in RStudio, a few things happen.

  • First, the R code is run, and the code and output (depending on your chunk options) are saved as TEX. This TEX also includes the non-R-code parts of your original RMD document (e.g., paragraphs, sections, etc.).
  • Then, pdfLatex (or luaLatex or whatever Latex engine you use) converts that TEX file to a PDF file.

Here's the process in pictures:


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


So finally, regarding your specific question. xtable's output is designed for that second step (the TEX file). When you call xtable(anthro_table_f) in RStudio, that table (in Latexy form) is printed to the R console.

DanY
  • 5,920
  • 1
  • 13
  • 33
  • Can someone with moderator privileges and knowledge of SO formatting please make my post more readable? I read up on how to change image sizes on SO, but I was unable to find an option that looked good. Thank you! – DanY Sep 16 '18 at 22:23
  • Ah I see- is there a way to get it to print in the actual form (non-Latexy) to the console? – Hank Lin Sep 17 '18 at 14:38
  • With `xtable`, no. With some other package, maybe, but I don't know of any. – DanY Sep 17 '18 at 15:57