forked from nhs-r-community/intro_r
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path03-workshop_import_data.Rmd
178 lines (114 loc) · 3.08 KB
/
03-workshop_import_data.Rmd
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
---
title: "Importing Data"
subtitle: "Session 3"
institute: "NHS-R Community"
output:
xaringan::moon_reader:
css:
- default
- css/nhsr.css
- css/nhsr-fonts.css
lib_dir: libs
seal: false
self_contained: true
nature:
highlightStyle: googlecode
highlightLines: true
highlightLanguage: ["r"]
countIncrementalSlides: false
ratio: "16:9"
includes:
after_body: [css/insert-logo.html]
---
```{r libs, include=FALSE}
library(knitr)
library(tidyverse)
library(xaringan)
library(xaringanExtra)
xaringanExtra::use_share_again() # need to get the slide button on html view
opts_chunk$set(
echo = FALSE,
eval = FALSE,
message = FALSE,
warning = FALSE,
fig.width = 7.252,
fig.height = 4,
dpi = 300,
dev.args = list(type = "cairo")
)
```
class: title-slide, left, bottom
# `r rmarkdown::metadata$title`
----
## **`r rmarkdown::metadata$subtitle`**
### `r rmarkdown::metadata$author`
### `r rmarkdown::metadata$date`
.right-column[
]
---
class: center, middle
# Import data to R
There are R packages to import all types of data.
In this course, we'll cover the most
common imports:
csvs and Excel workbooks
--
We'd like to import the `capacity_ae.csv` file.
While we could write code from scratch to do this,
it's often easier to get the import wizard to do this
for you.
---
class: center, middle
# Import data to R
We will use the "Import Dataset" button (but you can also click on the file itself):
<img class="center" src="img/session03/import-screenshot.PNG" width="80%"/>
---
# Import data to R
We will use the "Import Dataset" button:
<img class="center" src="img/session03/drop-down-import.PNG" width="60%"/>
---
# Import data to R
The package used to install csvs is {readr} which is loaded with the {tidyverse} package.
Excel workbooks require the package {readxl}.
<img class="center" src="img/session03/drop-down-import-csv.PNG" width="60%"/>
---
# Import wizard
Locate the file capacity_ae.csv
<img src="img/session03/wizard.PNG"/>
---
# Import wizard
<img src="img/session03/capacity-ae-preview.PNG"/>
---
# Import wizard
<img src="img/session03/import-button.PNG"/>
---
# Import wizard
<img src="img/session03/copy-wizard-code.PNG"/>
---
# Import wizard
<img src="img/session03/copy-code-preview.PNG"/>
---
# Import wizard
Once copied then select .green[Cancel] and then .green[Paste].
.left-col[.left[
From the clipboard:
<img class="center" src="img/session03/paste-code.PNG"/>
]]
--
.right-col-.right[
Where just one line copied:
<img src="img/session03/paste-selected-code.PNG"/>
]
---
# Run code from the editor
<img class="center" src="img/session03/run-code.PNG"/>
No need to highlight all code to run.
Put the cursor in the line you want to run then select the button to Run or <kbd> Ctrl + Return </kbd>
---
#### This work is licensed as
Creative Commons
Attribution
ShareAlike 4.0
International
To view a copy of this license, visit
https://creativecommons.org/licenses/by/4.0/