class: title-slide <br> <br> .right-panel[ # Introduction to R Markdown ## Dr. Mine Dogucu ] --- class: inverse middle center .font150[~~R~~ Markdown] --- ***R Markdown*** is a file format for making dynamic documents with R. An R Markdown document is written in markdown (an easy-to-write plain text format) and contains chunks of embedded R code. ***R Markdown*** files are the source code for rich, reproducible documents. --- class: inverse middle .font100[
= .R file] .font100[
= .md file] .font100[
+
= .Rmd file] --- .important[ You can transform an R Markdown file in two ways: ] - knit - You can knit the file. The rmarkdown package will call the knitr package. knitr will run each chunk of R code in the document and append the results of the code to the document next to the code chunk. - convert - You can convert the file. The rmarkdown package will use the pandoc program to transform the file into a new format. For example, you can convert your .Rmd file into an HTML, PDF, or Microsoft Word file. --- <img src="img/rmd-parts.jpeg" width="100%" /> --- class: center middle ## Add Chunk <img src="img/code-chunk.png" width="50%" /> --- class: center middle ## Run the Current Chunk <img src="img/run-code.png" width="20%" /> --- class: center middle ## Knit <img src="img/knit.png" width="50%" /> --- <img src="img/chunk.png" width="90%" /> --- ##Inline Code To embed R code in a line of text, surround the code with a pair of backticks and the letter r, like this. - Two plus two equals 4. <img src="img/rmd-inline.png" width="90%" /> --- # Inline Code Example ``` r cyl_prcnt <- mtcars %>% count(cyl) %>% mutate(prcnt = n/sum(n)*100) %>% filter(cyl == 4) %>% select(prcnt) ``` `$$\\[0.05in]$$` **34.375** percent of cars in our dataset have 4 cylinders. <img src="img/inline.png" width="60%" /> --- class: middle center ## Shortcuts | | Windows | Mac | |----------------------------|------------------|------------------| | add chunk | Ctrl + Alt + I | Cmd + Option + I | | run the current chunk | Ctrl + Alt + C | Cmd + Option + C | | run current line/selection | Ctrl + Enter | Cmd + Return | | knit | Ctrl + Shift + K | Cmd + Shift + K | --- class: middle ## Summary of our Tools **R** is a programming language used mainly for statistical computing. **markdown** is a markup language for creating formatted text. **R Markdown** is a file format that can handle R and markdown (and many other languages). **RStudio** is an integrated development environment (IDE). --- class: middle ## R vs. RStudio - You can write English (a language, so is R) words in a notebook (like RStudio). - But you can also write it elsewhere too (on a napkin, sand etc. or even in different notebooks). - R is a language that can be written in many different places, RStudio is just one of them. - There are many others.