@@ -7,11 +7,10 @@ editor_options:
7
7
chunk_output_type : console
8
8
---
9
9
10
- To get the most out of attending this tutorial, it will help if you have had the
11
- following experiences:
10
+ To get the most out of attending this tutorial, it will help if you have previous experience with:
12
11
13
- * Analyzed data with R in RStudio
14
- * Knit an R Markdown file in RStudio
12
+ * Analyzing data with R in RStudio
13
+ * Knitting an R Markdown file in RStudio
15
14
16
15
## R and RStudio
17
16
@@ -21,6 +20,8 @@ RStudio IDE.
21
20
22
21
[ rscloud ] : https://rstudio.cloud/
23
22
23
+ ![ ] ( assets/rstudio-panes.png )
24
+
24
25
In the top left is the editor pane. This is where you write your R code that is
25
26
saved to files on your computer.
26
27
@@ -50,6 +51,19 @@ Plots pane
50
51
51
52
* Viewer - This displays web content like the HTML created from R Markdown files
52
53
54
+ A very useful feature for interactively exploring your data while simultaneously
55
+ recording your steps is the ability to send lines of code from the file open in
56
+ the Editor directly to the R console to be executed. You can do this by clicking
57
+ on the button "Run" or using the keyboard shortcut Ctrl/Cmd+Enter.
58
+
59
+ In the gif below, I demonstrate both methods. First I define the vector ` x ` by
60
+ clicking the "Run" button. Notice how the Environment pane updates with the
61
+ newly defined object. Second I use the keyboard shortcut Ctrl+Enter to send the
62
+ second line of code to the R console. This plots a histogram of the data, which
63
+ is displayed in the Plots pane.
64
+
65
+ ![ ] ( assets/rstudio-send-code.gif )
66
+
53
67
For more information, check out the Software Carpentry lesson on [ Introduction
54
68
to R and
55
69
RStudio] ( https://swcarpentry.github.io/r-novice-gapminder/01-rstudio-intro/index.html ) .
@@ -58,7 +72,33 @@ RStudio](https://swcarpentry.github.io/r-novice-gapminder/01-rstudio-intro/index
58
72
59
73
When you open an R Markdown file in the editor pane, a button named "Knit" will
60
74
display. If you click on it, it will knit the document to HTML. You can view the
61
- progress in the newly created "R Markdown" tab in the bottom left. Another
62
- option for running the code is to click on the button "Run". You can run
75
+ progress in the newly created "R Markdown" tab in the bottom left.
76
+
77
+ In the gif below, I click the "Knit" button to knit the R Markdown file. I
78
+ include the chunk ` Sys.sleep(1) ` so that it pauses long enough for you to see
79
+ the R Markdown pane appear.
80
+
81
+ ![ ] ( assets/rstudio-knit.gif )
82
+
83
+ Another option for running the code is to click on the button "Run". You can run
63
84
individual chunks or "Run All". Furthermore, just like R scripts, you can send
64
85
individual lines to the R console with Ctrl/Cmd+Enter.
86
+
87
+ In the gif below, I execute all the code chunks by clicking "Run All". Note that
88
+ before I do this, I instruct RStudio to send the chunk output to the R console
89
+ instead of displaying it inline. This makes it easier to interactively develop
90
+ the code in the R console and keeps the file uncluttered.
91
+
92
+ ![ ] ( assets/rstudio-run-all.gif )
93
+
94
+ Lastly, it is important to understand how to interpret the error messages
95
+ produced when knitting R Markdown files, which you will use during the tutorial.
96
+
97
+ In the gif below, I knit an R Markdown file that produces an error trying to run
98
+ ` log("a") ` . The default view only displays the error message. I click on
99
+ "Output" to see the full log. This informs you the lines in the source R
100
+ Markdown file to check for the error. Importantly, it doesn't pinpoint the exact
101
+ line where the error occurred. Instead it reports the range of lines spanned by
102
+ the code chunk where the error occurred.
103
+
104
+ ![ ] ( assets/rstudio-knit-error.gif )
0 commit comments