0

Sorry for the novice question. I'm trying to create nice, presentable tables in R Markdown. I've seen a ton of packages such as xtable and stargazer that promise to create great graphs, but when I attempt to use them in my R Markdown code I see the code for a table...

% latex table generated in R 3.2.3 by xtable 1.8-2 package
% Fri May 20 14:47:39 2016
\begin{table}[ht]
\centering
\begin{tabular}{llll}
  \hline
 & Year & File & Gender\_PctNA \\ 
  \hline
1 & 2012 & Applicant & 22.2\% \\ 
  2 & 2012 & Participant & 0.1\% \\ 
  3 & 2013 & Applicant & 0\% \\ 
  4 & 2013 & Participant & 0.2\% \\ 
  5 & 2014 & Applicant & 0\% \\ 
  6 & 2014 & Participant & 0\% \\ 
  7 & 2015 & Applicant & 0.2\% \\  
  8 & 2015 & Participant & 0.2\% \\ 
   \hline
\end{tabular}
\end{table}

... but no table.

Obviously there is some intermediate step that I am completely missing, but for the life of me I cannot find anything online explaining this. Am I using the wrong program somehow? Is there some other way to produce tables that will actually be rendered in my Markdown report?

jaimedash
  • 2,683
  • 17
  • 30
ILA
  • 3
  • 1
  • 5
    You need to put `results = "asis"` in your code chunk header (for the tables; your question doesn't actually deal with graphs). – Bryan Hanson May 20 '16 at 21:39
  • Alternatively, you could use `knitr::asis_output (print(xtable (obj)))` or equivalent to accomplish the same thing as the `results = 'asis'` chunk option. This is a more useful trick when you have output in the same chunk that you don't want rendered asis. – Benjamin May 21 '16 at 02:50
  • Thanks for the input, all. Gregor was right, and the original thread does a better job of explaining this. For the record, I had success with `results = "asis"` in the header, and `obj %>% knitr::kable(format = "markdown")` to produce the table itself. `format = "html"` also worked as I'm producing an HTML file, but the formatting was off. – ILA May 23 '16 at 15:25

0 Answers0