forked from melissamonk-NOAA/Rmarkdown_workshop_2016
-
Notifications
You must be signed in to change notification settings - Fork 0
/
4-Workshop_examples.Rmd
203 lines (111 loc) · 4.27 KB
/
4-Workshop_examples.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
---
title: "Workshop Examples"
author: "Melissa Monk"
date: ''
output:
pdf_document:
fig_caption: yes
includes:
in_header: header.tex
keep_tex: yes
number_sections: yes
toc: yes
toc_depth: 4
documentclass: article
fontsize: 12pt
geometry: margin=1in
csl: CJFAS.csl
bibliography: BibFile.bib
link-citations: yes
---
```{r global_options, include=FALSE}
# set global options for R code chunks: echo=FALSE (don't include source code);
# warning=FALSE (suppress R warnings); message=FALSE (suppress R messages)
# eval = TRUE is default
# knitr::opts_chunk$set(echo = FALSE, warning = FALSE, message = FALSE)
library(xtable)
# options(xtable.comment = FALSE) # turns off xtable comments
```
Change some of the YAML settings to see what happens.
Notice, the down arrow at line 22. If you click this, you can hide the R code chunk. This is helpful when working through a large document.
On the right side of the R code chunk are additional options, Settings, a down arrow (run previous R code chunks), and a green play button (runs the current chunk). It's handy to check R code chunks as you go and to debug. Within the Assessment template, this is also the only way to see variables in your Environment.
# Epmhasis (R markdown and LaTeX)
# Headers
# Commenting
# Links
# Lists
<!--
R Markdown are finicky with spacing...
* Item 1
* Item 2
+ Item 2a
+ Item 2b
* Item 1
* Item 2
+ Item 2a
+ Item 2b
-->
<!--
Bulleted list
\begin{itemize}[noitemsep,nolistsep,topsep=0pt]
\item \href{https://git-scm.com/book/en/v2/Getting-Started-Installing-Git}{Git}
\item \href{https://cran.r-project.org/bin/windows/base/}{R}
\end{itemize}
-->
<!--
Numbered list
\begin{enumerate}[noitemsep,nolistsep,topsep=0pt]
\item \href{https://git-scm.com/book/en/v2/Getting-Started-Installing-Git}{Git}
\item \href{https://cran.r-project.org/bin/windows/base/}{R}
\end{enumerate}
-->
# References and Citations
We can reference a document section, see Lists in Section \ref{lists}.
Citations: [@Love2002]
#Figure from a file
You can use any file extension, including PDFs
![Here's my caption \label{fig:fig_example}](RMarkdownFLow.png)
Figures are referenced using LaTeX syntax \ref{fig:fig_example}.
Put a space between the ] and ( above. Knit the document.
Now try adding your own picture to the directory, adding it in here, and referencing it.
# R code chunks
You can embed an R code chunk like this:
```{r cars, echo=FALSE, include=F}
summary(cars)
```
Play witht the r code chunk options, echo=TRUE, include=FALSE, results='asis'
# Figure from R code chunk
You can also embed plots, for example:
```{r pressure, echo=FALSE, include=FALSE, fig.cap="Figure of something at $40^\\circ 10^\\prime$. \\label{fig:pressure}"}
plot(pressure)
```
Note, you need extra \\s when using LaTeX syntax within an R code chunk, or when inserting a backslash in R markdown. The same goes with percent signs and any other LaTeX reserved symbol.
<!--
We can now reference Figure \ref{fig:pressure}. Note where this text ends up.
Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.
-->
#Tables
```{r, results='asis', echo=FALSE, include=FALSE}
#, results='asis', echo=FALSE, include=FALSE, message=FALSE, warning=FALSE
Tab = read.csv('Table_example.csv')
Tab_example = xtable(Tab,
caption=c('This is where you write your caption'),
label = 'tab:Table_example')
print(Tab_example, include.rownames = FALSE, caption.placement = 'top')
# print option to try, scalebox = 0.7
# add alignment
```
Try changing the R chunk options above.
We can now reference Table \ref{tab:Table_example}.
Now, try putting the R code chunk within and HTML comment.
# Create you own table
Either create a .csv file or copy one into the repo folder on your computer.
Now, create a table!
#Math mode
<!--
You can use LaTeX math mode both inline and for inserting equations. It's handy for using inline math mode for management measure and lat/long.
Inline looks like this: $SPR_{40\%}$
*Note the % sign has a \ when used in math mode, but not in R markdown text.
To get degrees and minutes type: $40^\circ 10^\prime$
-->
#References