.Rmd
is Rstudio’s special blend of Markdown (a text
rendering language).md
is the more generic Markdown file type. In RStudio,
the intermediate .md
files are not (in the default state)
preserved.LaTeX
Typesetting language invented in the 1970s by
computer programmer Donald Knuth for proper rendering of text and
equations. Hundreds of commands. Precise, but somewhat complicated to
use.Markdown
Greatly simplified version of LaTeX with a
small number of commands to master. Easy to use, text looks great.yaml
1. Header material for .Rmd
files that can be changed manually or by selecting options.R
Computer language for manipulating numbers, text,
graphics, statistics..Rmd
file#
to ######
*numbering from
options*<text>*
**<text>**
~<text>~
^<text>^
~~<text>~~
>text with no closing mark
First Header | Second Header
------------- | -------------
Content Cell | Content Cell
Content Cell | Content Cell
kable
package for later{r, echo=TRUE,results='asis'}
library(knitr)
kable(head(iris))
Sepal.Length | Sepal.Width | Petal.Length | Petal.Width | Species |
---|---|---|---|---|
5.1 | 3.5 | 1.4 | 0.2 | setosa |
4.9 | 3.0 | 1.4 | 0.2 | setosa |
4.7 | 3.2 | 1.3 | 0.2 | setosa |
4.6 | 3.1 | 1.5 | 0.2 | setosa |
5.0 | 3.6 | 1.4 | 0.2 | setosa |
5.4 | 3.9 | 1.7 | 0.4 | setosa |
to shade
First Header | Second Header
------------- | -------------
Content Cell | Content Cell
Content Cell | Content Cell
kable
package for later{r, echo=TRUE,results='asis'}
library(knitr)
kable(head(iris))
Sepal.Length | Sepal.Width | Petal.Length | Petal.Width | Species |
---|---|---|---|---|
5.1 | 3.5 | 1.4 | 0.2 | setosa |
4.9 | 3.0 | 1.4 | 0.2 | setosa |
4.7 | 3.2 | 1.3 | 0.2 | setosa |
4.6 | 3.1 | 1.5 | 0.2 | setosa |
5.0 | 3.6 | 1.4 | 0.2 | setosa |
5.4 | 3.9 | 1.7 | 0.4 | setosa |
in-line $
centered $$
basic math and text spacing handled by LateX
$$y = a + b$$
\[y = a + b\]
$$H_0 = Z_{a + b}$$
\[H_0 = Z_{a + b}\]
$$S = cA^z$$
\[S = cA^z\]
\[S=cA^z_1 + z_{2 + x}\]
$$S=cA^z_1 + z_{2 + x}$$
\[\alpha = \frac{\beta}{\delta + \gamma_x}\]
$$\alpha = \frac{\beta}{\delta + \gamma_x}$$
\[z = \sum_{i=1}^X{K}\]
$$z = \sum_{i=1}^X{K}$$
Use \backslash
$$\backslash \alpha \le b \backslash$$
\[\backslash \alpha \le b \backslash\]
\[P(Occurrence Of Species A) = Z\]
$$P(Occurrence Of Species A) = Z$$
\[P(\mbox{Occurrence Of Species A}) = Z\]
$$P(\mbox{Occurrence Of Species A}) = Z$$
CTRL-ALT-I
inserts a new “chunk” of R code# Use comments extensively in ALL of your coding!
Pred <- seq(1,10) # make a vector of integers from 1 to 10
Res <- runif(10) # generate 10 draws from a random uniform (0,1) distribution
# print the random numbers
print(Res)
## [1] 0.2383757 0.4377084 0.5717281 0.6752646 0.2680563 0.6470778 0.3148969
## [8] 0.6643741 0.0141859 0.5488485
echo
and eval
to
control printing of code and output## [1] 9.799092 7.905844 8.292692 10.982835 9.774276 9.724717 10.017520
## [8] 9.563490 10.651323 11.543441
CTRL - ENTER
to run a single line of codeCTRL - SHIFT - ENTER
to source and echo the entire
scriptCTRL - SHIFT - S
to source entire script without
echoing console outputCTRL - SHIFT - C
comment and un-comment selected lines
of code# First comment to explain what this program is doing.
# Be expansive and describe it in great detail. This may seem trivial, but will become increasingly important as you create complex programs.
# Simple script to examine the distribution of the product of two uniform variables
# Make sure it is readable. Use complete sentences, not cryptic phrases.
# 6 September 2018
# NJG
# Preliminaries
library(ggplot2)
set.seed(100)
library(TeachingDemos) # use this to set the random number seed from a character string
char2seed("green tea")
char2seed("green tea",set=FALSE)
## [1] 7023541
#
# Global variables
nRep <- 10000
# Create or read in data
ranVar1 <- rnorm(nRep)
# print(ranVar1)
head(ranVar1)
## [1] -0.67595800 0.07142749 -0.13803318 -0.99300667 -1.17181879 0.51340840
## [1] 0.35209291 -0.11819204 0.57509922 -0.05122504 -1.98879289 -1.04776740
## Warning: `qplot()` was deprecated in ggplot2 3.4.0.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## [1] 10000
## num [1:10000] -1.3151 0.0117 0.1435 2.2531 -0.9411 ...
## [1] -1.31510790 0.01168855 0.14346105 2.25309300 -0.94114160 0.13995337
.R
files to .html
(creating an
R notebook)#
Purling
to strip and consolidate R chunks from a
Markdown filelibrary(knitr)
purl("FileName.Rmd")
These commands will create a file FileName.R
that has
all of the R code and none of the markdown text. R comments are still
retained.