-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathintro.qmd
131 lines (75 loc) · 4.25 KB
/
intro.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
---
execute:
eval: false
from: markdown+emoji
---
# Introduction
## What you will learn
How to:
- **Read** your hard-earned data into R
- **Wrangle and clean** the data in a R-friendly format
- **Produce** summary statistics
- **Analyse** your data
- **Visualise** your findings
Pre-analysis stages:
-
Analysis stages:
<!-- Some simply, yet profound conceptual diagram that shows the reader all these processes -->
## How book is organised
This book is organised by data type (e.g. [Survey data](survey.qmd), Questionnaire data).
Each chapter will walk through the process will work with real-world Psychology data and will walk you through reading in data, to cleaning and eventually analysis and visualising the results.
### Conventions
We will refer to packages as `{dplyr}` and functions as `mean()`. Variables and objects (such as file names or data objects) as `age` and `mtcars`. Where it would aid understanding, we will sometimes refer to functions within a particular packages as `dplyr::mutute()`
## Prerequisites
Content drawn from existing resources such as https://r4ds.hadley.nz/intro#prerequisites
### R
Download
Point to intro to R content (RUWithme, Environmental Computing, Software Carpentry)
### RStudio
RStudio projects
Point to resource about Rproj (SWC)
Running R code
https://r4ds.hadley.nz/intro#running-r-code
### Version control with git
#### What is git?
#### Why do I need git?
<!-- Point to Happy with git R -->
### R packages
Every code section will always begin with calls to R packages. There will be code that is commented out (have `#` preceding the code) for you to install these if you don't have them on your computer
```{r}
# install.packages(dplyr)
library(dplyr)
```
There are few R packages that will be on heavy rotation when it comes to working with Psychology data.
#### {tidyverse}
[{tidyverse}](https://www.tidyverse.org/) is a collection of R packages that is essential to a data scientist's toolkit. By installing `{tidyverse}` you are actually installing 8 other packages. The ones we will most often use include:
- [{dplyr}](https://dplyr.tidyverse.org/)
- [{ggplot2}](https://ggplot2.tidyverse.org/)
- [{tidyr}](https://tidyr.tidyverse.org/)
The handy thing is, when you load the `{tidyverse}` library into R, it will load the core suite of packages for you instead of you loading each of them independently! Efficiency!! :rocket:
```{r}
library(tidyverse)
```
Other packages that will be helpful for your R workflows include:
- [{here}](https://here.r-lib.org/)
- [{janitor}](http://sfirke.github.io/janitor/)
At the end of each chapter, we will also include our call to `sessionInfo()` so you can see what version of packages we are using.
## Virtual environments
Speaking on what package versions as we write this book, we understand the R package space is constantly changing. This means sometimes code will break due to package updates and this is all part of the process! To combat this problem, we've enlisted [`renv`](https://rstudio.github.io/renv/articles/renv.html#getting-started) to create a reproducible environment for building this book.
### Download our virtual environment
The virtual environment used to build this book is stored in a `lockfile`. You can find this file in the [GitHub repository](https://github.com/unsw-edu-au/r4psych) where the source code of this book lives.
The lockfile is named `renv.lock`. You can download this file directly but clicking on the file name and clicking on the "Download raw file" button.
![](images/renv.png)
Alternatively, you can [clone](https://happygitwithr.com/clone.html?q=clone#clone) our repository into your computer. Learn more about cloning repositorsies and other GitHub workflows in [Happy Git](https://happygitwithr.com/) by Jenny Bryan.
Once you have this file downloaded, move it in a relevant [project directory]() and then we can let `{renv}` work its magic.
### Install
First things first, lets install `renv` if we don't have it already.
```{r, eval}
install.packages("renv")
library(renv)
```
### Recreate virtual enviroment
Now let's tell `renv` where our downloaded `renv.lock` file is. Specific the path to the file in the function `restore()` and you are good to go!
```{r, eval=FALSE}
restore(lockfile = "path_to_renv.lock")
```