R markdown
A tool within RStudio that allows to
- write documents,
- presentations, or
- webpages that
combine written text with analytical code.
-Documents with embedded code are reproducible
-Pass on your code to readers in addition to the report content
-Dynamic documents can change as data are updated
-Documents can also be used for future data releases and/or different subsets of data
YAML can set:
- Font (size and style)
- Default figure options (height, width, etc.)
- Reference custom CSS (Cascading Style Sheets) Code
— title: "My Title" author: "Naimul" date: "August 10, 2016" output: html_document font-family: "Arial" css: customcss.css
—
A. R Markdown offers shorthand for formatting text:
- *italics* = italics
- **bold** = bold
- ~~strikethrough~~= strikethrough
- [BLS](www.bls.gov)= BLS
- superscript^2= superscript^2
- subscript^~2~= subscript^2
B. Use HTML code:
- <i>italics</i> = italics
- <b>bold</b> = bold
- #Header 1=
- ##Header 2=
- ###Header 3=
- ####Header 4=
C. Lists:
Unordered List
- Item
- Item
- Item
Ordered List
1. Item Number 1 2. Item Number 2 + Sub-item 3. Item Number 3
D. Line Breaks:
- End a line with two spaces.
- want more than one line between paragraphs, you need to use <br>
E. Mathematics in R Markdown:
Code => Formula
$x = y$=> \(x = y\)
$x < y$=> \(x < y\)
$x \le y$=> \(x \le y\)
$x \ge y$=> \(x \ge y\)
$x^{n}$=> \(x^{n}\)
$x_{n}$=> \(x_{n}\)
$\overline{x}$=> \(\overline{x}\)
$\hat{x}$=> \(\hat{x}\)
$\tilde{x}$=> \(\tilde{x}\)
$\frac{a}{b}$=> \(\frac{a}{b}\)
$\displaystyle \frac{a}{b}$=> \(\displaystyle \frac{a}{b}\)
$\binom{n}{k}$=> \(\binom{n}{k}\)
$x_{1} + x_{2} + \dots + x_{n}$=> \(x_{1} + x_{2} + \cdots + x_{n}\)
$x_{1}, x_{2}, \dots, x_{n}$=> \(x_{1}, x_{2}, \dots, x_{n}\)
$x \in A$=> \(x \in A\)
$|A|$=> \(|A|\)
$x \subset B$=> \(x \subset B\)
$x \subseteq B$=> \(x \subseteq B\)
$A \cup B$=> \(A \cup B\)
$A \cap B$=> \(A \cap B\)
$X \sim {\sf Binom}(n, \pi)$=> \(X \sim {\sf Binom}(n, \pi)\)
$\mathrm{P}(X \le x) = {\tt pbinom}(x, n, \pi)$=> \(\mathrm{P}(X \le x) = {\tt pbinom}(x, n, \pi)\)
$P(A \mid B)$=> \(P(A \mid B)\)
$x \in A$=> \(x \in A\)
$\{1, 2, 3\}$=> \(\{1, 2, 3\}\)
$\sin(x)$=> \(\sin(x)\)
$\log(x)$=> \(\log(x)\)
$\int_{a}^{b}$=> \(\int_{a}^{b}\)
$\left(\int_{a}^{b} f(x) \; dx\right)$=> \(\left(\int_{a}^{b} f(x) \; dx\right)\)
$\left[\int_{-\infty}^{\infty} f(x) \; dx\right]$=> \(\left[\int_{-\infty}^{\infty} f(x) \; dx\right]\)
$\left. F(x) \right|_{a}^{b}$=> \(\left. F(x) \right|_{a}^{b}\)
$\sum_{x = a}^{b} f(x)$=> \(\sum_{x = a}^{b} f(x)\)
$\prod_{x = a}^{b} f(x)$=> \(\prod_{x = a}^{b} f(x)\)
$\lim_{x \to \infty} f(x)$=> \(\lim_{x \to \infty} f(x)\)
$\displaystyle \lim_{x \to \infty} f(x)$=> \(\displaystyle \lim_{x \to \infty} f(x)\)
$$\alpha, \beta, \gamma, \Gamma$$=> \(\alpha, \beta, \gamma, \Gamma\)
$$a \pm b$$=> \(a \pm b\)
$$a_i \ge 0~~~\forall i$$=> \(a_i \ge 0~~~\forall i\)
$$\mathbf{X} = \left[\begin{array}{rrr}1 & 2 & 3 \\4 & 5 & 6 \\7 & 8 & 9\end{array}\right]$$=>
\[\mathbf{X} = \left[\begin{array} {rrr} 1 & 2 & 3 \\ 4 & 5 & 6 \\ 7 & 8 & 9 \end{array}\right] \]
' ' ' {r}
SOME CODE GOES HERE
' ' '
Code Chunk Options
name - This is not necessary
echo -
echo=FALSE; code embedded, but the reader can’t see it
echo=TRUE; code embedded, but the reader can see it
eval -
echo=FALSE; display the code and run
echo=TRUE; display the code but not have it run
warning -
warning=FALSE; Do not display warning
warning=TRUE; display warning
message -
message=FALSE; Do not display message
message=TRUE; display message
results -
results=FALSE; Do not display results
results=TRUE; display results
A. Add image:
Code:
{r, echo=FALSE, out.width="20%", fig.cap="R markdown"} knitr::include_graphics("D:/Drive/1. Happy Life/Daily/4. Markdown/rmarkdown.png")
R markdown