Open ksedivyhaley opened 8 years ago
From skimming that document I wonder if you have your pander and/or chunk options set correctly? That seems to be important. Maybe post an actual example? It's hard to tell what's wrong from the above.
Setup line created by RStudio:
knitr::opts_chunk$set(echo = TRUE)
Load packages, settings:
suppressPackageStartupMessages(library(tidyverse))
library(gapminder)
library(knitr)
library(pander)
panderOptions('round', 2)
panderOptions('keep.trailing.zeros', TRUE)
panderOptions('knitr.auto.asis', TRUE) #this is what the page described
Create table:
gapminder %>%
group_by(continent) %>%
summarise(gdp_pc_min = min(gdpPercap),
gdp_pc_mean = mean(gdpPercap),
gdp_pc_max = max(gdpPercap)) %>%
pandoc.table(style = "rmarkdown")
I also tried looking at the actual md document and noticed that the table is being produced inside a code chunk (without an {r} tag, commented out). which explains why markdown doesn't think it should be formatted, but not why it's showing up inside a chunk and the kable() tables aren't.
I tried this out and I got pandoc.table()
to output the table, but treated as a console output. However, with pander()
it rendered properly in the markdown output.
gapminder %>%
group_by(continent) %>%
summarise(gdp_pc_min = min(gdpPercap),
gdp_pc_mean = mean(gdpPercap),
gdp_pc_max = max(gdpPercap)) %>%
pander(style = "rmarkdown")
output:
continent | gdp_pc_min | gdp_pc_mean | gdp_pc_max |
---|---|---|---|
Africa | 241.2 | 2194 | 21951 |
Americas | 1201.6 | 7136 | 42952 |
Asia | 331.0 | 7902 | 113523 |
Europe | 973.5 | 14469 | 49357 |
Oceania | 10039.6 | 18622 | 34435 |
Is this what you were looking for, or did I misinterpret your question?
In summary:
That's exactly it, thanks!
I started with this documentation which uses pandoc.table() and displayed tables as console output but missed the fact that the second one with the nice output switched to pander().
I'm getting pander output that looks like this:
This source says that pander's output is supposed to interpret markdown as long as knitr is running in the background. Should I be doing something other than simply calling library(knitr) or hitting the Knit button in rstudio to make sure that knitr is running?