Skip to content

Commit b6df9b5

Browse files
committed
Add demo of running all chunks in a saved workspace.
1 parent a551685 commit b6df9b5

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

analysis/challenge.Rmd

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,30 @@ steps:
3232

3333
The analysis purposefully contains various issues that make it difficult to
3434
reproduce. Open the file `spotify.Rmd` by clicking on it in the RStudio Files
35-
pane. Click the Knit button to re-run the analysis and find the first issue.
35+
pane. In the Editor pane, click on "Run" and then click on "Run All" to execute
36+
all the code chunks in the R console (Ctrl/Cmd+Alt+Enter). Note that the code
37+
completes and produces a plot in the Plots pane.
38+
39+
Next click the Knit button to re-build the document. This time the code fails
40+
due to an error. The difference is because RStudio knits Rmd files in a clean
41+
R session. In contrast, the R session currently running in the R console already
42+
had all the analysis variables created because the workspace was restored. This
43+
is why you want to avoid saving your workspace: it can make it appear that your
44+
code is running when it is actually contains errors. In fact, if you scroll
45+
back up through the R console history, you'll see that some errors did occur.
46+
But the analysis still completed since the intermediate objects were already
47+
available.
48+
49+
To fix the workspace issue, first go to the Files pane and delete the file
50+
`.RData` that contains the saved workspace. Second, go to "Tools" -> "Global
51+
Options...". Unclick the checkbox "Restore .RData into workspace at startup" and
52+
change the dropdown "Save workspace to to .RData on exit" to Never.
53+
54+
![](assets/rstudio-workspace.png)
55+
56+
Now you can proceed to fix the analysis one error at a time. Click on Knit to
57+
produce the first error. Then click on "Output" to see the lines in the Rmd
58+
file where the error occurred.
3659

3760
## File paths
3861

docs/assets/rstudio-workspace.png

91 KB
Loading

0 commit comments

Comments
 (0)