Skip to content

Commit c2c51f4

Browse files
committed
Continue working on section to create workflowr project.
1 parent b6df9b5 commit c2c51f4

File tree

1 file changed

+114
-25
lines changed

1 file changed

+114
-25
lines changed

analysis/workflowr.Rmd

Lines changed: 114 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
title: "Create a workflowr project"
33
author: "John Blischak"
44
date: "2020-06-17"
5-
output: workflowr::wflow_html
5+
output:
6+
workflowr::wflow_html:
7+
toc: false
68
editor_options:
79
chunk_output_type: console
810
---
@@ -11,91 +13,178 @@ editor_options:
1113
knitr::opts_chunk$set(eval = FALSE)
1214
```
1315

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].
1620

1721
[vig-getting-started]: https://jdblischak.github.io/workflowr/articles/wflow-01-getting-started.html
1822

23+
Start by loading the workflowr package in the R console.
24+
1925
```{r package}
2026
library(workflowr)
2127
```
2228

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+
2336
```{r git-config}
2437
# Replace the example text with your information
2538
wflow_git_config(user.name = "Your Name", user.email = "email@domain")
2639
```
2740

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.
2861

2962
```{r start}
30-
wflow_start(".", name = "Spotify song analysis", existing = TRUE)
63+
wflow_start(directory = ".", name = "Spotify song analysis", existing = TRUE)
3164
```
3265

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
4076
```
4177

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+
4285
```{r build}
4386
wflow_build()
4487
```
4588

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/`.
4799

48100
```{r move-files}
49101
file.rename("spotify.Rmd", "analysis/spotify.Rmd")
50102
file.rename("spotify.csv", "data/spotify.csv")
51103
```
52104

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:
54110

55111
```
56112
spotify <- read.csv("data/spotify.csv", stringsAsFactors = FALSE)
57113
```
58114

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}
60119
wflow_build()
61120
```
62121

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?
64124

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.
66128

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.
68141

69142
```{r status}
70143
wflow_status()
71144
```
72145

73-
Add link in `index.Rmd`:
146+
![](https://f1000researchdata.s3.amazonaws.com/manuscripts/22923/510c4de2-c96e-4471-9853-4ebce466a666_figure4.gif)
74147

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.
78151

79152
```
80153
[Link to spotify analysis](spotify.html)
81154
```
82155

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.
86159

87160
```{r publish}
88161
wflow_publish(c("analysis/*Rmd", "data/spotify.csv"), "Add spotify analysis")
89162
```
90163

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+
91172
```{r status-2}
92173
wflow_status()
93174
```
94175

95176
Create [new repository on GitHub](https://github.com/new)
96177

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+
97186
```{r git-push}
98187
wflow_git_push()
99188
```
100189

101-
Activate GitHub Pages
190+
Go to "Settings" and activate GitHub Pages.

0 commit comments

Comments
 (0)