-
Notifications
You must be signed in to change notification settings - Fork 66
/
minimal.brew
92 lines (60 loc) · 2.18 KB
/
minimal.brew
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
% 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](https://johnmacfarlane.net/pandoc/README.html#title-block) or just use `pandoc.title` function of this package.
As you can see writing and formatting paragraphs cannot be easier :)
But what about [R](https://www.r-project.org/)? 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`](https://rapporter.github.io/pander/#pander-options)!
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)) {
histogram(mtcars$hp)
}
%>
The above `lattice` looks (IMHO) pretty cool, but what about using `base` plot?
<%=
hist(mtcars$hp)
%>
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?')
histogram(mtcars$hp)
panderOptions('graph.grid.color', temp)
%>
# Captions
Just like with tables:
<%=
set.caption('Here goes the first two lines of USArrests')
USArrests[1:2,]
%>
# Multiple results
And the chunks can result in multiple R objects of course:
<%=
list(1:5)
list(pi)
list(mtcars$hp)
%>
# It happens
<%=
mean(unknown.R.object)
%>