March 8, 2017

agenda

  • why use markdown and RMarkdown
  • author an RMarkdown html presentation
  • then quickly use code above to author an RMarkdown word document

this is a new slide to test

  • basic GIS concepts
    • intro to projections and transformations
      • more stuff

  • "Get, get, get markdown" Nasir Jones, God's Son, 2002
  • Source wikipedia

what is markdown

why use markdown

  • allows reproducibility
  • good workflow to author documents
    • same syntax can be used to create multiple documents
    • word documents, presentations, html webpages
  • easily used within RStudio—RMarkdown

steps to create an RMarkdown document

  1. open a new .Rmd document
  2. write document
  3. knit document
  4. preview output
  5. publish

optional
6. examine build log & use output file

RMarkdown Cheatsheet

open a new .Rmd document :

  • many options available…

open a new .Rmd document: options

recommended for docs

recommended for docs

recommended for ppts

recommended for ppts

open a new .Rmd document: default document (presentations)

open a new .Rmd document: default document (presentations)

  1. title page slide
  2. checks if RMarkdown needs to be setup
  3. the 1st slide — only includes text and some formatting
  4. the 2nd slide — includes bullets
  5. the 3st slide — develops data summary within a "code chunk"
  6. the 4th slide — develops plot summary within a "code chunk"

write document

write document: subsections

  • for presentations subsections are new slides
  • for word documents subsections are subsections
  • subsection denoted by ##

write document: bullets

  • numbered lists are simply written as: 1. 2. 3. etc.
  • unordered bullets and subsequent sub-bullets are written as:
  • *
    • +
      • -
  • use double tab to indent sub-bullets
    • 4 tabs to indent sub-sub-bullets
  • end each bulleted statement with a double space!

write document: formatting text

  • italics written as *word here*
  • bold written as **word here**
  • strikethrough written as ~~word here~~
  • superscript written as ^word here^
  • subscript written as ~word here~
  • there is no underlining

write document: formatting text

  • en dash uses 2 hyphens –
  • em dash uses 3 hyphens —

write document: hyperlinks

write document: escaping special characters

  • we just reviewed some special characters for bullets and formatting text
  • how do we stop the character from being oh so special?
  • use the escape character—a backslash before a special character: \
    • lets stop italics within RMarkdown e.g., \*italics\*
  • another option is to put text within back quotes

write document: formatting slides

  • some formatting only makes sense for presentations
    • for example to split a slide into 2 we need to use html tags
      • start the slide with this: <div class="columns-2">
      • end the slide with this: </div>
      • forcing the content into 2 slides is trial and error (play with line spacing between subsections)

write document: inserting code

  • two ways
    • verbatim using the back quote `code here`
      • e.g., summary(cars)
    • use code chunks
      • first line is ```{r}
      • code here
      • last line is ```
    • code chunks can actually evaluate data!
summary(cars)
##      speed           dist       
##  Min.   : 4.0   Min.   :  2.00  
##  1st Qu.:12.0   1st Qu.: 26.00  
##  Median :15.0   Median : 36.00  
##  Mean   :15.4   Mean   : 42.98  
##  3rd Qu.:19.0   3rd Qu.: 56.00  
##  Max.   :25.0   Max.   :120.00

write document: code chunks

  • there are many options for code chunks
  • some resources:
  • some useful code chunk arguments include echo=, eval=, include=
    • default for all 3 is TRUE
    • by default, your code is evaluated and within the document is echo'd or repeated, and output is included

```{r echo = TRUE, eval = TRUE, include = TRUE}
summary(cars)
```

write document: code chunks to create a table

```{r echo = FALSE}
col1 = c("coolness level", "community support")
col2 = c("high", "high")
col3 = c("low", "low")
df <- cbind(col1,col2,col3)
colnames(df) <- c("what's different?","R","SAS")
knitr::kable(df,padding=0)
```

what's different? R SAS
coolness level high low
community support high low

write document: code chunks to add a picture

```{r echo = FALSE, out.width = "350px"}
knitr::include_graphics("filepath of any jpeg or other figure")
```

knit document

  • click on knit within RStudio
  • let's choose ioslides

preview document

  • preview pops-up automatically
  • examine all the slides

preview document

  • click on the publish button
  • create an Rpubs account

take a break 5 minute break

  • then let's work together on developing a couple of slides for your presentation

finally let's create a word document from your same code!

recommended for docs

recommended for docs

  • after RStudio generates your default code, copy and paste contents below
  • and knit!

next week

  • spring break
  • consider watching: The Get Down
    • executive produced by Nasir Jones
    • we may have a bonus quiz question regarding this Netflix show
      • will test your ability to Google stuff—beacuse well—you're scientists