Fetching contributors…
Cannot retrieve contributors at this time
93 lines (60 sloc) 2.18 KB
% Gergely Daróczi
% Minimal example for `Pandoc.brew`
# Introduction
We have two meta-information above:
* author
* title
A third field could be there too: date. For details, please check out [Pandoc's homepage]( or just use `pandoc.title` function of this package.
As you can see writing and formatting paragraphs cannot be easier :)
But what about [R]( Let us return pi: <%=pi%>
# R objects
`Pander.brew` would transform any returned R object to Pandoc's markdown in each code block.
For example `mtcars`'s first 5 cases look like:
<%=mtcars[1:5, ]%>
As you can see some formatting was added to the returned table and was also split up as the original table would have been too wide to fit on the screen (any `pander`er still using a VT100 terminal?) or standard paper. If you do not like that split up, just set the according [`panderOption`](!
We could try other R objects too, for example let us check `chisq.test` on some variables of `mtcars`:
<%=chisq.test(mtcars$am, mtcars$gear)%>
And we got a warning above!
## Returning plot
Plots are automatically grabbed between `brew` tags and some custom formatting applied (if `evalsOptions('graph.unify')` is set to `TRUE`):
if (require(lattice, quietly = TRUE)) {
The above `lattice` looks (IMHO) pretty cool, but what about using `base` plot?
This should be quite similar by my intention :)
What about `ggplot2`?
if (require(ggplot2, quietly = TRUE)) {
ggplot(mtcars) + geom_histogram(aes(x = hp))
And adding a caption is easy with even some modified `panderOptions`:
temp <- panderOptions('graph.grid.color')
panderOptions('graph.grid.color', 'red')
set.caption('This is a caption, right?')
panderOptions('graph.grid.color', temp)
# Captions
Just like with tables:
set.caption('Here goes the first two lines of USArrests')
# Multiple results
And the chunks can result in multiple R objects of course:
# It happens