-
Notifications
You must be signed in to change notification settings - Fork 15
/
outline.qmd
214 lines (110 loc) · 6.08 KB
/
outline.qmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
---
title: "Outline for R/data-science workshop"
date-modified: 'today'
date-format: long
license: CC BY-NC
bibliography: references.bib
---
## Why R / Tidyverse / Quarto
We're going to learn about one of the best tool-based ecosystems for orchestrating and sharing our reproducible computational thinking. A major tennant of reproducibility is to *do everything with code*. This include generating our reports from code (Quarto) as well as importing data, wrangling, modeling, and visualizing data (Tidyverse.)
R and the [Tidyverse](https://www.tidyverse.org/) are a powerful language for data analysis[^1]. In addition to a wide range of built in functions there are thousands of library packages[^2] we can use in custom programming to extend R into specialized areas of computation.
[^1]: R is a data-first programming language
[^2]: Extend R with domain-specific **packages**. See: [MetaCran](https://www.r-pkg.org/), [CRAN](https://cran.r-project.org/), github, [bioconductor](https://www.bioconductor.org/)
Based on a weekly [schedule](schedule.html), we will learn tidyverse tools and techniques to transform our data into the [tidy data format](https://r4ds.had.co.nz/tidy-data.html), a consistent format for data organization, manipulation, and analysis.
This workshop series is sponsored by The Center for Data and Visualization Sciences, part of the Duke University Libraries. Videos and links to code, data, and slides for this and many other R workshops can be found at [Rfun](https://rfun.library.duke.edu). These and all other CDVS all workshop resources are available at the [CDVS online learning page](https://library.duke.edu/data/tutorials).
### Getting started
- **Reproducibility**: data-first tools help leverage reproducible workflows throughout computational thinking
- Do everything with code
- Organize our work into [RStudio **Projects**](projects.html)
- [blank-slate](https://docs.posit.co/ide/user/ide/get-started/#blank-slate) instead of .Rdata
- Restart instead of `rm(list = ls())`
- Version Control: git and GitHub
- {`renv`} for archiving/documenting package environments
- Tool suite
- RStudio
- Quarto Notebooks (Merge literate coding with report rendering)
- {`dplyr`} & {`tidyr`} - a grammar for data wrangling
- {`ggplot2`} - a grammar of graphics
- Other packages including, for example: {`readr`}, {`forcats`}, {`stringr`}, {`purrr`}, {`tidymodels`}
- Console
- basic computation
- vectors and vectorized math
- environment variables and data variables
- **assignment** operators: `<-` and `=` (not the same as equivalency `==`)
- **pipe**s = `|>` and `%>%`
- RStudio [Projects](https://docs.posit.co/ide/user/ide/guide/code/projects.html)
- use projects instead of `setwd()` ; relative paths are vital to reproducibility
- Documents: Quarto document
- Import CSV data
- `read_csv()` and the data import wizard found in *Files* tab and *Environment* tab
- Other data formats
- {`readxl`}, {`haven`}
- SQL
- Code-chunks can perform SQL
- {`dbplyr`}
- [Best Practices with Databases](https://solutions.posit.co/connections/db/)
- **Exercise**
- import a CSV file
- import a Stata categorical file using {*haven*}
- {`dplyr`}
- select(), filter(), arrange(), mutate(), group_by(), summarize(), count()
- **Exercise**
- Semantic meaning in data
- Codebooks in a literate coding context
\
### Visualization plus EDA
- {ggplot2} viz
- **Exercise**
- basic interactivity - ggplotly()
- **Exercise**
- {`broom`} and handling modeling outputs (e.g. linear regression)
- Advertise {`tidymodels`}
- **Exercise**
- {skimr} and EDA
- skim()
- Reprise group_by() and summarize()
- {`tidyr`} pivot_longer() and pivot_wider()
- **Tall data** - what is it?
- Tall data for iteration: computation
- Tall data for visualization , facet_wrap()
- Tall data for modeling ; {purrr} a first look.
- join with `dplyr::left_join()` or other {`dplyr`} join functions
- Wrap-up and Summarize the day
### Iteration and custom functions
- Questions from yesterday
- R is a functional programming language
- What is functional programing?
- Customizing functions and iterating without FOR loops
- FOR loops?
- Tidyverse preference for data frames
- Vectorized math (review)
- Vectorized iteration ; environment variables and data variables
- Case study - import multiple data files + data cleaning + analysis + visualization
- read_csv() again
- Introduce {`stringr`} and regular expressions
- Some nifty data wrangling functions
- Composing custom functions
- Nesting data for iteration\
### Review, questions, case study, reports
- Questions / Review
- Setup case study
- Using R to orchestrate data workflows
- Reproducible report rendering (slides, PDF, dashboards, etc.)
- Summarize
- Finding help
## Resources
- R for Data Science: [book](https://r4ds.had.co.nz/) \| [slack](https://www.rfordatasci.com/)
- Tidyverse [primers](https://posit.cloud/learn/primers)
- RStudio IDE \> Help \> \[ Documentation \| Forum \| Cheatsheets \| Shortcuts \] & on-board *Help* tab
- [RStudio User Guide](https://docs.posit.co/ide/user/)
- Tidyverse webpages: {`package_name`}.tidyverse.org (e.g. ggplot2.tidyverse.org)
- Interactivity
- [HTMLWidgets](https://www.htmlwidgets.org)
- [ObservableJS](https://quarto.org/docs/interactive/ojs/)
- [Shiny](https://shiny.rstudio.com/)
## Recommendations
- [Blank slate](https://docs.posit.co/ide/user/ide/get-started/#blank-slate)
- Use the Projects in the RStudio IDE
- Use version control (git and GitHub) with {[usethis](https://usethis.r-lib.org/)}
- Use {[`renv`](https://rstudio.github.io/renv/index.html)} for package reproducible environments
- Use {[fs](https://fs.r-lib.org/ "file system manipulation via R")} for working with file systems