The pander package gives you access to all the Pandoc options you can handle. Seems like a big mountain to climb, but once you get started it’s actually not too rough.
In particular, the pandoc.[WHATEVER]()
functions from pander make it easy to render nicely formatted objects in R Markdown.
An example … say you had the following character vector:
bowie <- c("Young Americans", "Station To Station", "Low", "Heroes", "Lodger", "Scary Monsters", "Let's Dance")
You could just print the object:
bowie
## [1] "Young Americans" "Station To Station" "Low"
## [4] "Heroes" "Lodger" "Scary Monsters"
## [7] "Let's Dance"
Doesn’t look great. Maybe try it with the generic pander()
function around the name of the character vector:
# install.packages("pander")
library(pander)
pander(bowie)
Young Americans, Station To Station, Low, Heroes, Lodger, Scary Monsters and Let’s Dance
Still not great, but until a couple days ago that’s probably where I would have left it.
Then I tab-completed into the pandoc.[WHATEVER]()
functions and realized I was doing it wrong …
In this case if I want a list then I should go with pandoc.list()
:
pandoc.list(bowie)
##
## * Young Americans
## * Station To Station
## * Low
## * Heroes
## * Lodger
## * Scary Monsters
## * Let's Dance
##
## <!-- end of list -->
That looks more like a list … at least as it would be printed in a console.
If you want to see it bulleted just wrap another pander()
around it:
pander(pandoc.list(bowie))
- Young Americans
- Station To Station
- Low
- Heroes
- Lodger
- Scary Monsters
- Let’s Dance
And if you want to see the vector ordered:
pander(pandoc.list(bowie, style="ordered"))
- Young Americans
- Station To Station
- Low
- Heroes
- Lodger
- Scary Monsters
- Let’s Dance
The best part about these functions is that they’re documented inside R man pages (as opposed to only in the generic pandoc documentation):
?pandoc.list