---
title: An Introduction to R and RStudio for Exploratory Data Analysis
author: "Jessica Minnier, PhD & Meike Niederhausen, PhD<br><span style = 'font-size: 80%;'>[OCTRI Biostatistics, Epidemiology, Research & Design (BERD) Workshop](https://www.ohsu.edu/octri/octri-research-forum-your-monthly-clinical-and-translational-research-event) </span>"
date: "<span style = 'font-size: 80%;'>Part 1: 2020/09/16 & Part 2: 2020/09/17 <br><br><br> slides: [bit.ly/berd_intro_part2](http://bit.ly/berd_intro_part2) <br> pdf: [bit.ly/berd_intro_part2_pdf](http://bit.ly/berd_intro_part2_pdf)</span>"
output: 
  xaringan::moon_reader:
    css: [css/xaringan-themer.css, css/my-theme.css]
    lib_dir: libs
    nature:
      highlightStyle: tomorrow #http://arm.rbind.io/slides/xaringan.html#77
      highlightLines: true
      highlightLanguage: r
      countIncrementalSlides: false
      titleSlideClass: ["left", "middle", "inverse"]
      ratio: "16:10"
    includes:
      in_header: ../header.html   
editor_options: 
  chunk_output_type: console
---

layout: true
  
<!-- <div class="my-footer"><span>bit.ly/berd_tidy</span></div>  -->

---

```{r setup, include=FALSE}
options(htmltools.dir.version = FALSE)

library(tidyverse)
library(lubridate)
library(janitor)
library(emo)
library(here)

knitr::opts_chunk$set(
  warning=FALSE, 
  message=FALSE, 
  #fig.width=10.5, 
  #fig.height=4,
  fig.align = "center",
  rows.print=7,
  echo=TRUE,
  highlight = TRUE,
  # prompt = TRUE, # IF TRUE adds a > before each code input
  # comment = NA # PRINTS IN FRONT OF OUTPUT, default is '##' which comments out output
  comment = '##'
  )

# set ggplot theme
# theme_set(theme_bw(base_size = 24))
```

```{r xaringan-themer, include = FALSE}
# creates xaringan theme
# devtools::install_github("gadenbuie/xaringanthemer")
library(xaringanthemer)
mono_light(
  base_color =  "#3A6185", ## OHSU Marquam
  code_highlight_color = "#cbdded",
  link_color = "#38BDDE",
  header_font_google = google_font("Josefin Sans"),
  text_font_google   = google_font("Montserrat", "300", "300i","400i","700"),
  code_font_google   = NULL,
  text_font_size = "24px",
  code_font_size = "20px",
  header_h1_font_size = "45px",
  header_h2_font_size = "40px",
  header_h3_font_size = "35px",
  padding = "0em 2em 1em 2em",
  outfile = "css/xaringan-themer.css"
)
```

```{r, include=FALSE}
library(tidyverse)
library(janitor)
penguins <- read_csv(here::here("01-intro-r-eda","data","penguins.csv"))
mydata <- read_csv(here::here("01-intro-r-eda","data","yrbss.csv"))

```


## An Introduction to R and RStudio for Exploratory Data Analysis (Part 2)

Instructors: Meike Niederhausen, PhD & Jessica Minnier, PhD<br>
[OCTRI Biostatistics, Epidemiology, Research & Design (BERD) Workshop](https://www.ohsu.edu/octri/octri-research-forum-your-monthly-clinical-and-translational-research-event)

### *Do this now:*

1. **Open html slides**: [http://bit.ly/berd_intro_part2](http://bit.ly/berd_intro_part2)
1. **Download Rmd file** to follow along: [bit.ly/berd_intro_rmd](http://bit.ly/berd_intro_rmd)
1. **Open google doc** for asking questions: [bit.ly/berd_doc2](https://bit.ly/berd_doc2)
  + Helpers will be monitoring this, you can ask questions, copy code or screenshots.
1. **Open Rstudio with these steps:**
  + Open the folder from yesterday
  + Double click on the `.Rproj` file.
  + All your files should be there.

---

# Working with data, continued

.pull-left[
- Open your old Rmd file
- If you make a new Rmd file, make sure you have this code in a code chunk at the top of the Rmd:

```{r, eval = FALSE}
library(tidyverse)
library(janitor)
penguins <- read_csv("penguins")
```

- Remember we need to load (open) the package every time we want to use it in a new Rstudio instance *or* knit an Rmd
- When you knit an Rmd, it is blind to what you have done in the console or in the R enivronment. It starts completely from scratch.
]
.pull-right[
<img src="img/rmd_penguins.png" width="100%" height="80%">
]

```{r child=here::here("01-intro-r-eda","child_pipe_summaries.Rmd")}
# Jessica
```

```{r child=here::here("01-intro-r-eda","child_practice3.Rmd")}
# Jessica - with pipe/summaries; stop day 1
```

```{r child=here::here("01-intro-r-eda","child_wrangling.Rmd")}
# Meike
```

```{r child=here::here("01-intro-r-eda","child_practice4.Rmd")}
# Meike - mutate/filter etc
```


```{r child=here::here("01-intro-r-eda","child_ggplot.Rmd")}
#Jessica
```

```{r child=here::here("01-intro-r-eda","child_practice5.Rmd")}
# Jessica
```

```{r child=here::here("01-intro-r-eda","child_factors.Rmd")}
# Meike
```

```{r child=here::here("01-intro-r-eda","child_closing.Rmd")}
#Jessica
```



```{r, eval=FALSE, echo=FALSE}
# RUN THESE AFTER KNITTING
knitr::purl(here::here("01-intro-r-eda","01_intro_r_eda_part2.Rmd"), 
            out = here::here("01-intro-r-eda","01_intro_r_eda_part2.R"))
# remotes::install_github('rstudio/pagedown')
pagedown::chrome_print(here::here("01-intro-r-eda","01_intro_r_eda_part2.html"))
```
