-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrstudio-programming-environment.html
303 lines (262 loc) · 17.9 KB
/
rstudio-programming-environment.html
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
<!DOCTYPE html>
<html lang="" xml:lang="">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>3 RStudio Programming Environment | Programming for Data Analysis and Statistics with R</title>
<meta name="description" content="3 RStudio Programming Environment | Programming for Data Analysis and Statistics with R" />
<meta name="generator" content="bookdown 0.20 and GitBook 2.6.7" />
<meta property="og:title" content="3 RStudio Programming Environment | Programming for Data Analysis and Statistics with R" />
<meta property="og:type" content="book" />
<meta name="twitter:card" content="summary" />
<meta name="twitter:title" content="3 RStudio Programming Environment | Programming for Data Analysis and Statistics with R" />
<meta name="author" content="Diren Senger" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<link rel="prev" href="installation-notes.html"/>
<link rel="next" href="r-data-types.html"/>
<script src="book_assets/jquery-2.2.3/jquery.min.js"></script>
<link href="book_assets/gitbook-2.6.7/css/style.css" rel="stylesheet" />
<link href="book_assets/gitbook-2.6.7/css/plugin-table.css" rel="stylesheet" />
<link href="book_assets/gitbook-2.6.7/css/plugin-bookdown.css" rel="stylesheet" />
<link href="book_assets/gitbook-2.6.7/css/plugin-highlight.css" rel="stylesheet" />
<link href="book_assets/gitbook-2.6.7/css/plugin-search.css" rel="stylesheet" />
<link href="book_assets/gitbook-2.6.7/css/plugin-fontsettings.css" rel="stylesheet" />
<link href="book_assets/gitbook-2.6.7/css/plugin-clipboard.css" rel="stylesheet" />
<style type="text/css">
a.sourceLine { display: inline-block; line-height: 1.25; }
a.sourceLine { pointer-events: none; color: inherit; text-decoration: inherit; }
a.sourceLine:empty { height: 1.2em; }
.sourceCode { overflow: visible; }
code.sourceCode { white-space: pre; position: relative; }
pre.sourceCode { margin: 0; }
@media screen {
div.sourceCode { overflow: auto; }
}
@media print {
code.sourceCode { white-space: pre-wrap; }
a.sourceLine { text-indent: -1em; padding-left: 1em; }
}
pre.numberSource a.sourceLine
{ position: relative; left: -4em; }
pre.numberSource a.sourceLine::before
{ content: attr(data-line-number);
position: relative; left: -1em; text-align: right; vertical-align: baseline;
border: none; pointer-events: all; display: inline-block;
-webkit-touch-callout: none; -webkit-user-select: none;
-khtml-user-select: none; -moz-user-select: none;
-ms-user-select: none; user-select: none;
padding: 0 4px; width: 4em;
color: #aaaaaa;
}
pre.numberSource { margin-left: 3em; border-left: 1px solid #aaaaaa; padding-left: 4px; }
div.sourceCode
{ }
@media screen {
a.sourceLine::before { text-decoration: underline; }
}
code span.al { color: #ff0000; font-weight: bold; } /* Alert */
code span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
code span.at { color: #7d9029; } /* Attribute */
code span.bn { color: #40a070; } /* BaseN */
code span.bu { } /* BuiltIn */
code span.cf { color: #007020; font-weight: bold; } /* ControlFlow */
code span.ch { color: #4070a0; } /* Char */
code span.cn { color: #880000; } /* Constant */
code span.co { color: #60a0b0; font-style: italic; } /* Comment */
code span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */
code span.do { color: #ba2121; font-style: italic; } /* Documentation */
code span.dt { color: #902000; } /* DataType */
code span.dv { color: #40a070; } /* DecVal */
code span.er { color: #ff0000; font-weight: bold; } /* Error */
code span.ex { } /* Extension */
code span.fl { color: #40a070; } /* Float */
code span.fu { color: #06287e; } /* Function */
code span.im { } /* Import */
code span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */
code span.kw { color: #007020; font-weight: bold; } /* Keyword */
code span.op { color: #666666; } /* Operator */
code span.ot { color: #007020; } /* Other */
code span.pp { color: #bc7a00; } /* Preprocessor */
code span.sc { color: #4070a0; } /* SpecialChar */
code span.ss { color: #bb6688; } /* SpecialString */
code span.st { color: #4070a0; } /* String */
code span.va { color: #19177c; } /* Variable */
code span.vs { color: #4070a0; } /* VerbatimString */
code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */
</style>
</head>
<body>
<div class="book without-animation with-summary font-size-2 font-family-1" data-basepath=".">
<div class="book-summary">
<nav role="navigation">
<ul class="summary">
<li class="chapter" data-level="1" data-path="about.html"><a href="about.html"><i class="fa fa-check"></i><b>1</b> About</a></li>
<li class="chapter" data-level="2" data-path="installation-notes.html"><a href="installation-notes.html"><i class="fa fa-check"></i><b>2</b> Installation Notes</a></li>
<li class="chapter" data-level="3" data-path="rstudio-programming-environment.html"><a href="rstudio-programming-environment.html"><i class="fa fa-check"></i><b>3</b> RStudio Programming Environment</a><ul>
<li class="chapter" data-level="3.1" data-path="rstudio-programming-environment.html"><a href="rstudio-programming-environment.html#creating-a-new-project"><i class="fa fa-check"></i><b>3.1</b> Creating a new project</a></li>
<li class="chapter" data-level="3.2" data-path="rstudio-programming-environment.html"><a href="rstudio-programming-environment.html#rstudio-screen"><i class="fa fa-check"></i><b>3.2</b> RStudio screen</a></li>
<li class="chapter" data-level="3.3" data-path="rstudio-programming-environment.html"><a href="rstudio-programming-environment.html#r-workflow"><i class="fa fa-check"></i><b>3.3</b> R Workflow</a></li>
</ul></li>
<li class="chapter" data-level="4" data-path="r-data-types.html"><a href="r-data-types.html"><i class="fa fa-check"></i><b>4</b> R Data types</a><ul>
<li class="chapter" data-level="4.1" data-path="r-data-types.html"><a href="r-data-types.html#character"><i class="fa fa-check"></i><b>4.1</b> Character</a></li>
<li class="chapter" data-level="4.2" data-path="r-data-types.html"><a href="r-data-types.html#numeric"><i class="fa fa-check"></i><b>4.2</b> Numeric</a></li>
<li class="chapter" data-level="4.3" data-path="r-data-types.html"><a href="r-data-types.html#logical"><i class="fa fa-check"></i><b>4.3</b> Logical</a></li>
<li class="chapter" data-level="4.4" data-path="r-data-types.html"><a href="r-data-types.html#vectors"><i class="fa fa-check"></i><b>4.4</b> Vectors</a></li>
<li class="chapter" data-level="4.5" data-path="r-data-types.html"><a href="r-data-types.html#factors"><i class="fa fa-check"></i><b>4.5</b> Factors</a></li>
<li class="chapter" data-level="4.6" data-path="r-data-types.html"><a href="r-data-types.html#list-of-lists"><i class="fa fa-check"></i><b>4.6</b> List of lists</a></li>
<li class="chapter" data-level="4.7" data-path="r-data-types.html"><a href="r-data-types.html#matrices"><i class="fa fa-check"></i><b>4.7</b> Matrices</a></li>
<li class="chapter" data-level="4.8" data-path="r-data-types.html"><a href="r-data-types.html#data-frames"><i class="fa fa-check"></i><b>4.8</b> Data frames</a></li>
</ul></li>
<li class="chapter" data-level="5" data-path="preparing-your-data-for-analysis.html"><a href="preparing-your-data-for-analysis.html"><i class="fa fa-check"></i><b>5</b> Preparing your data for analysis</a><ul>
<li class="chapter" data-level="5.1" data-path="preparing-your-data-for-analysis.html"><a href="preparing-your-data-for-analysis.html#reading-the-data"><i class="fa fa-check"></i><b>5.1</b> Reading the data</a></li>
<li class="chapter" data-level="5.2" data-path="preparing-your-data-for-analysis.html"><a href="preparing-your-data-for-analysis.html#transforming-entire-columns"><i class="fa fa-check"></i><b>5.2</b> Transforming entire columns</a></li>
<li class="chapter" data-level="5.3" data-path="preparing-your-data-for-analysis.html"><a href="preparing-your-data-for-analysis.html#subsetting-data"><i class="fa fa-check"></i><b>5.3</b> Subsetting data</a></li>
<li class="chapter" data-level="5.4" data-path="preparing-your-data-for-analysis.html"><a href="preparing-your-data-for-analysis.html#useful-functions"><i class="fa fa-check"></i><b>5.4</b> Useful functions</a></li>
</ul></li>
<li class="chapter" data-level="6" data-path="conditions-if-and-else.html"><a href="conditions-if-and-else.html"><i class="fa fa-check"></i><b>6</b> Conditions - If and Else</a><ul>
<li class="chapter" data-level="6.1" data-path="conditions-if-and-else.html"><a href="conditions-if-and-else.html#if"><i class="fa fa-check"></i><b>6.1</b> If</a></li>
</ul></li>
<li class="chapter" data-level="7" data-path="for-and-while.html"><a href="for-and-while.html"><i class="fa fa-check"></i><b>7</b> For and While</a><ul>
<li class="chapter" data-level="7.1" data-path="for-and-while.html"><a href="for-and-while.html#for"><i class="fa fa-check"></i><b>7.1</b> For</a></li>
<li class="chapter" data-level="7.2" data-path="for-and-while.html"><a href="for-and-while.html#while"><i class="fa fa-check"></i><b>7.2</b> While</a></li>
<li class="chapter" data-level="7.3" data-path="for-and-while.html"><a href="for-and-while.html#do-while"><i class="fa fa-check"></i><b>7.3</b> Do-while</a></li>
<li class="chapter" data-level="7.4" data-path="for-and-while.html"><a href="for-and-while.html#for-vs.while"><i class="fa fa-check"></i><b>7.4</b> For vs. While</a></li>
</ul></li>
<li class="chapter" data-level="8" data-path="writing-own-functions.html"><a href="writing-own-functions.html"><i class="fa fa-check"></i><b>8</b> Writing own functions</a></li>
<li class="chapter" data-level="9" data-path="debugging.html"><a href="debugging.html"><i class="fa fa-check"></i><b>9</b> Debugging</a></li>
<li class="chapter" data-level="10" data-path="piping.html"><a href="piping.html"><i class="fa fa-check"></i><b>10</b> Piping</a></li>
<li class="chapter" data-level="11" data-path="plotting.html"><a href="plotting.html"><i class="fa fa-check"></i><b>11</b> Plotting</a><ul>
<li class="chapter" data-level="11.1" data-path="plotting.html"><a href="plotting.html#standard-library"><i class="fa fa-check"></i><b>11.1</b> Standard library</a><ul>
<li class="chapter" data-level="11.1.1" data-path="plotting.html"><a href="plotting.html#points-or-lines-type"><i class="fa fa-check"></i><b>11.1.1</b> Points or Lines? (type)</a></li>
<li class="chapter" data-level="11.1.2" data-path="plotting.html"><a href="plotting.html#line-type-lty"><i class="fa fa-check"></i><b>11.1.2</b> Line type (lty)</a></li>
</ul></li>
<li class="chapter" data-level="11.2" data-path="plotting.html"><a href="plotting.html#ggplot"><i class="fa fa-check"></i><b>11.2</b> ggplot</a></li>
</ul></li>
<li class="chapter" data-level="12" data-path="r-markdown.html"><a href="r-markdown.html"><i class="fa fa-check"></i><b>12</b> R-Markdown</a><ul>
<li class="chapter" data-level="12.1" data-path="r-markdown.html"><a href="r-markdown.html#output-formats"><i class="fa fa-check"></i><b>12.1</b> Output formats</a></li>
<li class="chapter" data-level="12.2" data-path="r-markdown.html"><a href="r-markdown.html#document-structure"><i class="fa fa-check"></i><b>12.2</b> Document structure</a></li>
<li class="chapter" data-level="12.3" data-path="r-markdown.html"><a href="r-markdown.html#code-blocks"><i class="fa fa-check"></i><b>12.3</b> Code blocks</a></li>
<li class="chapter" data-level="12.4" data-path="r-markdown.html"><a href="r-markdown.html#lists"><i class="fa fa-check"></i><b>12.4</b> Lists</a></li>
<li class="chapter" data-level="12.5" data-path="r-markdown.html"><a href="r-markdown.html#insert-an-image"><i class="fa fa-check"></i><b>12.5</b> Insert an image</a></li>
<li class="chapter" data-level="12.6" data-path="r-markdown.html"><a href="r-markdown.html#further-documentation"><i class="fa fa-check"></i><b>12.6</b> Further documentation</a></li>
</ul></li>
<li class="chapter" data-level="13" data-path="short-statistical-breaks.html"><a href="short-statistical-breaks.html"><i class="fa fa-check"></i><b>13</b> Short statistical breaks</a><ul>
<li class="chapter" data-level="13.1" data-path="short-statistical-breaks.html"><a href="short-statistical-breaks.html#dinosours"><i class="fa fa-check"></i><b>13.1</b> Dinosours</a></li>
<li class="chapter" data-level="13.2" data-path="short-statistical-breaks.html"><a href="short-statistical-breaks.html#stars"><i class="fa fa-check"></i><b>13.2</b> Stars</a></li>
<li class="chapter" data-level="13.3" data-path="short-statistical-breaks.html"><a href="short-statistical-breaks.html#correlation"><i class="fa fa-check"></i><b>13.3</b> Correlation</a></li>
<li class="chapter" data-level="13.4" data-path="short-statistical-breaks.html"><a href="short-statistical-breaks.html#beginners-book"><i class="fa fa-check"></i><b>13.4</b> Beginners Book</a></li>
</ul></li>
</ul>
</nav>
</div>
<div class="book-body">
<div class="body-inner">
<div class="book-header" role="navigation">
<h1>
<i class="fa fa-circle-o-notch fa-spin"></i><a href="./">Programming for Data Analysis and Statistics with R</a>
</h1>
</div>
<div class="page-wrapper" tabindex="-1" role="main">
<div class="page-inner">
<section class="normal" id="section-">
<div id="rstudio-programming-environment" class="section level1">
<h1><span class="header-section-number">3</span> RStudio Programming Environment</h1>
<div id="creating-a-new-project" class="section level2">
<h2><span class="header-section-number">3.1</span> Creating a new project</h2>
<p>In many statistics classes they teach you, that you should set a working directory:</p>
<div class="sourceCode" id="cb1"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb1-1" data-line-number="1"><span class="kw">setwd</span>(<span class="st">"~/Documents/"</span>)</a></code></pre></div>
<p>It can be helpful to create a project instead. All files within the project’s directory will automatically have the correct working directory. In this way you can create new files and start coding easily.</p>
<ol style="list-style-type: decimal">
<li>Click File -> New Project…
Even when you choose “Existing Directory” you will still be able to create a new directory
<img src="images/project1.png" alt="Creating a Project, Step 1" /></li>
<li>Enter the diretory path straight away, or click on browse.
<img src="images/project2.png" alt="Creating a Project, Step 2" /></li>
<li>Choose an existing directory or create a new one
<img src="images/project3.png" alt="Creating a Project, Step 3" /></li>
</ol>
</div>
<div id="rstudio-screen" class="section level2">
<h2><span class="header-section-number">3.2</span> RStudio screen</h2>
<ul>
<li>In the upper left hand corner you have the code editor. This is where you can type your scripts.</li>
<li>In the bottom left hand corner you have the console. Here you will see the results of all commands you are running.</li>
<li>In the upper right hand corner you can see all objects you created, e.g. data frames, functions, strings, …</li>
<li>In the bottom left hand corner you will be able to see the files in your project, your plots and more information e.g. about functions
<img src="images/rstudio.png" alt="RStudio screen" /></li>
</ul>
<p>You can use “Ctrl” followed by a number to jump to a specific window. If you want to get into the terminal use “Shift+Alt+t”.
<img src="images/rstudioNumbers.png" alt="RStudio screen" /></p>
</div>
<div id="r-workflow" class="section level2">
<h2><span class="header-section-number">3.3</span> R Workflow</h2>
<ul>
<li>You type your scripts in the code editor, so that you can save them.</li>
<li>If you want to run the whole script, you can click on ‘Source’ at the tope of the code editor or press “Ctrl + Alt + R”.</li>
<li>Use “Ctrl + Alt + B/E” to run from the beginning to the current line or from the current line to the end.</li>
<li>If you want to run a single line, you can click on ‘Run’ or press “Control + Enter”</li>
<li>If you want to run a few lines, highlight the lines you want to run and use ‘Run’/ “Control + Enter”</li>
<li>If you want to use Autocomplete, you can press “Control + Space”</li>
<li>If you want to read about an existing method, you can type “?<Name of the method>” to get to the documentation</li>
</ul>
</div>
</div>
</section>
</div>
</div>
</div>
<a href="installation-notes.html" class="navigation navigation-prev " aria-label="Previous page"><i class="fa fa-angle-left"></i></a>
<a href="r-data-types.html" class="navigation navigation-next " aria-label="Next page"><i class="fa fa-angle-right"></i></a>
</div>
</div>
<script src="book_assets/gitbook-2.6.7/js/app.min.js"></script>
<script src="book_assets/gitbook-2.6.7/js/lunr.js"></script>
<script src="book_assets/gitbook-2.6.7/js/clipboard.min.js"></script>
<script src="book_assets/gitbook-2.6.7/js/plugin-search.js"></script>
<script src="book_assets/gitbook-2.6.7/js/plugin-sharing.js"></script>
<script src="book_assets/gitbook-2.6.7/js/plugin-fontsettings.js"></script>
<script src="book_assets/gitbook-2.6.7/js/plugin-bookdown.js"></script>
<script src="book_assets/gitbook-2.6.7/js/jquery.highlight.js"></script>
<script src="book_assets/gitbook-2.6.7/js/plugin-clipboard.js"></script>
<script>
gitbook.require(["gitbook"], function(gitbook) {
gitbook.start({
"sharing": {
"github": false,
"facebook": true,
"twitter": true,
"linkedin": false,
"weibo": false,
"instapaper": false,
"vk": false,
"all": ["facebook", "twitter", "linkedin", "weibo", "instapaper"]
},
"fontsettings": {
"theme": "white",
"family": "sans",
"size": 2
},
"edit": {
"link": null,
"text": null
},
"history": {
"link": null,
"text": null
},
"view": {
"link": null,
"text": null
},
"download": null,
"toc": {
"collapse": "subsection"
},
"search": false
});
});
</script>
</body>
</html>