2
2
title : " Create a workflowr project"
3
3
author : " John Blischak"
4
4
date : " 2020-06-17"
5
- output : workflowr::wflow_html
5
+ output :
6
+ workflowr::wflow_html :
7
+ toc : false
6
8
editor_options :
7
9
chunk_output_type : console
8
10
---
@@ -11,91 +13,178 @@ editor_options:
11
13
knitr::opts_chunk$set(eval = FALSE)
12
14
```
13
15
14
- Modified version of workflowr vignette
15
- [ Getting started with workflowr] [ vig-getting-started ]
16
+ Now that you have the Spotify analysis running, you will create a workflowr
17
+ project to share the results and make sure it stays reproducible.
18
+ This is a modified version of the official workflowr vignette
19
+ [ Getting started with workflowr] [ vig-getting-started ] .
16
20
17
21
[ vig-getting-started ] : https://jdblischak.github.io/workflowr/articles/wflow-01-getting-started.html
18
22
23
+ Start by loading the workflowr package in the R console.
24
+
19
25
``` {r package}
20
26
library(workflowr)
21
27
```
22
28
29
+ Workflowr uses Git to version all the changes to the code and results. For each
30
+ version it snapshots, Git requires a user name and email for attribution. Thus
31
+ before creating the workflowr project, tell Git your name and email address you
32
+ would like to use. It is convenient if the email address is the same one you
33
+ used to register with GitHub, but not required. This command only has to be run
34
+ once per computer (i.e. not every time you create a new workflowr project).
35
+
23
36
``` {r git-config}
24
37
# Replace the example text with your information
25
38
wflow_git_config(user.name = "Your Name", user.email = "email@domain")
26
39
```
27
40
41
+ You can run ` wflow_git_config() ` again with no arguments to confirm that Git is
42
+ configured properly.
43
+
44
+ ``` {r git-config-confirm}
45
+ wflow_git_config()
46
+ ```
47
+
48
+ Now that Git is configured, you can start your workflowr project using
49
+ ` wflow_start() ` . It is more common to start a workflowr proejct in a brand new
50
+ directory, but the workflowr setup can also be added to an existing analysis. To
51
+ limit the tutorial to one RStudio Cloud project, you will create the workflowr
52
+ project in the same directory where you've already been working on the Spotify
53
+ analysis.
54
+
55
+ The first argument to ` wflow_start() ` is the directory. The command below uses
56
+ the relative path ` . ` , which refers to the current working directory. In this
57
+ case it is equivalent to using the absolute path ` /cloud/project/ ` . The second
58
+ argument is the name of the project, which will get displayed on the website.
59
+ And the third argument informs ` wflow_start() ` that the directory already
60
+ exists, since by default it expects to create a new one.
28
61
29
62
``` {r start}
30
- wflow_start(".", name = "Spotify song analysis", existing = TRUE)
63
+ wflow_start(directory = ".", name = "Spotify song analysis", existing = TRUE)
31
64
```
32
65
33
- ``` output
34
- wflow_start:
35
- - Files added to existing directory /cloud/project
36
- - Project name is "Spotify song analysis"
37
- - Working directory changed to /cloud/project
38
- - Git repo initiated at /cloud/project
39
- - Files were committed in version 838de5f
66
+ That adds various files and directories. For the purpose of the tutorial, focus
67
+ on the following subset:
68
+
69
+ ```
70
+ ├── _workflowr.yml # workflowr-specific settings
71
+ ├── analysis/ # Rmd files
72
+ │ ├── index.Rmd # Creates website homepage
73
+ │ └── _site.yml # website-specific settings
74
+ ├── data/ # data files
75
+ ├── docs/ # website files
40
76
```
41
77
78
+ The most important thing to remember is to perform your analysis in Rmd files in
79
+ ` analysis/ ` , and that the website files are saved in ` docs/ ` .
80
+
81
+ To see the default state of the website, run ` wflow_build() ` . It will build all
82
+ the Rmd files currently in ` analysis/ ` and save the HTML files in ` docs/ ` . The
83
+ website will either pop up in a new window or be displayed in the Viewer pane.
84
+
42
85
``` {r build}
43
86
wflow_build()
44
87
```
45
88
46
- Move files
89
+ Conveniently, if you run it a second time, it does nothing because the Rmd files
90
+ have not changed since the last time the HTML files were built.
91
+
92
+ ``` {r build-nothing}
93
+ wflow_build()
94
+ ```
95
+
96
+ Next add the Spotify analysis files to the workflowr project. You can do this
97
+ via the files Pane or the running the commands below in the R console. The Rmd
98
+ file goes to ` analysis/ ` and the data file to ` data/ ` .
47
99
48
100
``` {r move-files}
49
101
file.rename("spotify.Rmd", "analysis/spotify.Rmd")
50
102
file.rename("spotify.csv", "data/spotify.csv")
51
103
```
52
104
53
- Update path in ` spotify.Rmd ` :
105
+ And since ` spotify.csv ` is no longer in the same directory as ` spotify.Rmd ` ,
106
+ you need to update the path passed to ` read.csv() ` . By default, all Rmd files
107
+ in a workflowr project are executed in the root of the project, so the updated
108
+ path is ` data/spotify.csv ` . Open ` analysis/spotify.Rmd ` and change the import
109
+ line to the line below:
54
110
55
111
```
56
112
spotify <- read.csv("data/spotify.csv", stringsAsFactors = FALSE)
57
113
```
58
114
59
- ``` {r build-2}
115
+ Run ` wflow_build() ` again. This will build ` analysis/spotify.Rmd ` and then open
116
+ the new file ` docs/spotify.html ` .
117
+
118
+ ``` {r build-spotify}
60
119
wflow_build()
61
120
```
62
121
63
- Check results - everyone should get same numbers
122
+ Check the accuracy of the decision tree model and the random guessing model.
123
+ Did you obtain the same results as everyone?
64
124
65
- Look at the reproducibility report
125
+ This is because workflowr automatically sets the seed at the beginning of each
126
+ Rmd file. The default seed used for a project is the date in the format
127
+ ` YYYYMMDD ` . Open the file ` _workflowr.yml ` to confirm.
66
128
67
- Open ` _workflowr.yml ` to show the seed that is set
129
+ Also, you can look at the reproducibility report at the top of the file to see
130
+ the seed that is set and all the other reproducibility checks. The first check
131
+ is failing because the Rmd file hasn't been versioned with Git yet.
132
+
133
+
134
+
135
+
136
+ So far you've run ` wflow_build() ` multiple times. This builds the HTML files, but
137
+ it doesn't version anything with Git. Run ` wflow_status() ` to see the current
138
+ status of the Rmd files. The default Rmd files are "Unpublished" because they
139
+ have been versioned with Git, but not their HTML files. The new ` spotify.Rmd ` is
140
+ "Scratch" because its Rmd has not been versioned yet.
68
141
69
142
``` {r status}
70
143
wflow_status()
71
144
```
72
145
73
- Add link in ` index.Rmd ` :
146
+ ![ ] ( https://f1000researchdata.s3.amazonaws.com/manuscripts/22923/510c4de2-c96e-4471-9853-4ebce466a666_figure4.gif )
74
147
75
- ``` {r link}
76
- wflow_open(" analysis/index.Rmd")
77
- ```
148
+ There currently isn't a convenient way to navigate to the Spotify analysis on
149
+ the website. To fix this, open ` analysis/index.Rmd ` , add the line below, and
150
+ run ` wflow_build() ` again.
78
151
79
152
```
80
153
[Link to spotify analysis](spotify.html)
81
154
```
82
155
83
- ``` {r github}
84
- wflow_use_github("username", repository = "workflowr-spotify", create_on_github = FALSE)
85
- ```
156
+ The line above is markdown syntax to create a link to the file ` spotify.html ` .
157
+
158
+ Now that the website is looking good, it is time to "publish" your results.
86
159
87
160
``` {r publish}
88
161
wflow_publish(c("analysis/*Rmd", "data/spotify.csv"), "Add spotify analysis")
89
162
```
90
163
164
+ ` wflow_publish() ` performs three steps:
165
+
166
+ 1 . Commits the Rmd files and data file with Git
167
+ 1 . Executes the code to build the HTML files
168
+ 1 . Commits the HTML files with Git
169
+
170
+ Re-running ` wflow_status() ` shows that all the files are "published":
171
+
91
172
``` {r status-2}
92
173
wflow_status()
93
174
```
94
175
95
176
Create [ new repository on GitHub] ( https://github.com/new )
96
177
178
+ Configure Git remote
179
+
180
+ ``` {r git-remote}
181
+ wflow_git_remote("origin", user = "<github-username>", repo = "workflowr-spotify")
182
+ ```
183
+
184
+ Push to GitHub. Enter username and password.
185
+
97
186
``` {r git-push}
98
187
wflow_git_push()
99
188
```
100
189
101
- Activate GitHub Pages
190
+ Go to "Settings" and activate GitHub Pages.
0 commit comments