-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathiris_data_set_vm3.rmd
87 lines (71 loc) · 4.43 KB
/
iris_data_set_vm3.rmd
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
---
params:
doc_version: x.y
altplot: !r TRUE
title: "`r paste0('iris_data_set_vm3 v',params$doc_version)`"
author: "Han Oostdijk (www.hanoostdijk.nl)"
date: "`r format(Sys.time(), '%d %B, %Y')`" # current date
graphics: yes
linkcolor: blue
output:
pdf_document:
fig_caption: yes
includes:
in_header:
- styles.tex
- extra1.tex
before_body: extra2.tex
keep_tex: no
highlight: tango
geometry:
- a4paper
- landscape
toc: true
toc_depth: 2
knit: (function(inputFile, encoding) {rmarkdown::render(inputFile,encoding=encoding,clean=T,output_file = 'Iris_data_set_vm3.pdf') })
---
```{r child='iris_data_set_bib1.rmd'}
```
# Introduction
See the Introduction pdf for the various examples and the relation of this example to the others.
In this example we use additional \LaTeX \ packages to
* set the default font to be sans-serif (via include of \mytextbf{header.tex})
* load the package \mytextit{subfig} so that in a chunk two figures can be placed side by side (via include of \mytextbf{header.tex})
* (re) define some text macros (via include of \mytextbf{header.tex})
* redefine some of the colors that are used for highlighting the R-code and its background (via include of \mytextbf{header.tex}).
With one of these settings the background color was made darker so that it would be just visible when the document is printed.
* load and set some attributes of the package \mytextit{fancyhdr} that enables the use of headers and footers (via include of \mytextbf{extra1.tex})
* set additional attributes for \mytextit{fancyhdr} (via the chunk \mytextbf{setheader} in iris_data_set_bib1.rmd)
We have structured these \LaTeX \ commands in three separate groups:
* in the external permanent file \mytextbf{header.tex} the commands that go in the \LaTeX \ preamble part and don't change for each document
* in the internal file \mytextbf{extra1.tex} the commands that go in the \LaTeX \ preamble part and are specific for this document
* in the internal file \mytextbf{extra2.tex} the commands that go in front of the \LaTeX \ body part and are specific for this document.
In our examples no contents: a candidate for inclusion would be the \BSLASH{chead} command but because the header is not constant (see next paragraph) we need to use an engine_R chunk and not a engine_cat chunk.
Apart from these \LaTeX \ changes we also show what can be done in the yaml-header:
* define your own parameters by using the \mytextit{params} keyword:
+ we use the \mytextit{doc\_version} parameter to include a version number in the header of each page
+ we use the \mytextit{altplot} parameter to change the program flow by changing some text and including or omitting a figure.
We do this by setting some text variables dependent on the parameter and using the parameter to decide about executing and echoing chunks.
* specify e.g. the page orientation by using the \mytextit{geometry} keyword
* specify that a table of contents is to be included
* specify the \mytextit{knit} command that will be executed. Here we use it to explicitly specify the name of the pdf-file and to ensure that the intermediate md-file is not removed after processing. By specifying \mytextit{keep\_tex: yes} the intermediate tex-file will also be kept. This can be useful for debugging when the output is not as expected.
We also show here how to use an internal bibliography. This is a list of references that we include at the end of the document.
You can also use (and reuse) a bibliography that is stored in an external file. Handling of that is shown in the next example.
# Load data and create plot object
Before plotting the iris data set ( `r ref_tab('r1a',F)`) we list the first `r numlist`
(because we set variable \mytextit{numlist} to `r numlist` in a chunck we do not present to the reader)
observations in the data set `r ref_tab('lbltab1',T)`.
As an example of a reference we use \cite{myrefa} with another reference in a footnote\footnote{see \cite{myrefb}}.
NB. we now have to use the \LaTeX \ \mytextbf{\BSLASH{cite}} and \mytextbf{\BSLASH{footnote}} commands explicitly.
```{r child='iris_data_set_bib2.rmd'}
```
```{r echo=F,results='asis'}
# to include References in the table of contents
#cat('\\cleardoublepage')
#cat('\\phantomsection')
cat('\\addcontentsline{toc}{section}{References}')
```
\begin{thebibliography}{20}
\bibitem[author1]{myrefa} example of reference for author1
\bibitem[author2]{myrefb} example of reference for author2
\end{thebibliography}