-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathintroduction.html
More file actions
567 lines (526 loc) · 53.5 KB
/
Copy pathintroduction.html
File metadata and controls
567 lines (526 loc) · 53.5 KB
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
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
<!DOCTYPE html>
<html lang="" xml:lang="">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>1 Introduction | Best Coding Practices in R</title>
<meta name="description" content="This book provides a comprehensive guide to best coding practices in R, focusing on essential aspects like script organisation, naming conventions, commenting, and version control. It aims to enhance the readability, maintainability, and collaborative potential of R code by offering practical advice on creating well-structured and clean scripts." />
<meta name="generator" content="bookdown 0.40 and GitBook 2.6.7" />
<meta property="og:title" content="1 Introduction | Best Coding Practices in R" />
<meta property="og:type" content="book" />
<meta property="og:description" content="This book provides a comprehensive guide to best coding practices in R, focusing on essential aspects like script organisation, naming conventions, commenting, and version control. It aims to enhance the readability, maintainability, and collaborative potential of R code by offering practical advice on creating well-structured and clean scripts." />
<meta name="github-repo" content="rstudio/bookdown-demo" />
<meta name="twitter:card" content="summary" />
<meta name="twitter:title" content="1 Introduction | Best Coding Practices in R" />
<meta name="twitter:description" content="This book provides a comprehensive guide to best coding practices in R, focusing on essential aspects like script organisation, naming conventions, commenting, and version control. It aims to enhance the readability, maintainability, and collaborative potential of R code by offering practical advice on creating well-structured and clean scripts." />
<meta name="author" content="Daniel Hammocks, Senior Data Scientist at Mayor’s Office for Policing and Crime" />
<meta name="date" content="2024-08-28" />
<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="index.html"/>
<link rel="next" href="naming-conventions.html"/>
<script src="libs/jquery-3.6.0/jquery-3.6.0.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/fuse.js@6.4.6/dist/fuse.min.js"></script>
<link href="libs/gitbook-2.6.7/css/style.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-table.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-bookdown.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-highlight.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-search.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-fontsettings.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-clipboard.css" rel="stylesheet" />
<link href="libs/anchor-sections-1.1.0/anchor-sections.css" rel="stylesheet" />
<link href="libs/anchor-sections-1.1.0/anchor-sections-hash.css" rel="stylesheet" />
<script src="libs/anchor-sections-1.1.0/anchor-sections.js"></script>
<style type="text/css">
pre > code.sourceCode { white-space: pre; position: relative; }
pre > code.sourceCode > span { line-height: 1.25; }
pre > code.sourceCode > span:empty { height: 1.2em; }
.sourceCode { overflow: visible; }
code.sourceCode > span { color: inherit; text-decoration: inherit; }
pre.sourceCode { margin: 0; }
@media screen {
div.sourceCode { overflow: auto; }
}
@media print {
pre > code.sourceCode { white-space: pre-wrap; }
pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; }
}
pre.numberSource code
{ counter-reset: source-line 0; }
pre.numberSource code > span
{ position: relative; left: -4em; counter-increment: source-line; }
pre.numberSource code > span > a:first-child::before
{ content: counter(source-line);
position: relative; left: -1em; text-align: right; vertical-align: baseline;
border: none; 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 {
pre > code.sourceCode > span > a:first-child::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 { color: #008000; } /* 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 { color: #008000; font-weight: bold; } /* 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>
<style type="text/css">
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
</style>
<link rel="stylesheet" href="style.css" type="text/css" />
</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="toc-logo"><a href="./"><img src="images/MOPAC-DS-Square.png"></a></li>
<li class="divider"></li>
<li class="chapter" data-level="" data-path="index.html"><a href="index.html"><i class="fa fa-check"></i>Preface</a>
<ul>
<li class="chapter" data-level="" data-path="index.html"><a href="index.html#purpose-of-this-book"><i class="fa fa-check"></i>Purpose of this Book</a></li>
<li class="chapter" data-level="" data-path="index.html"><a href="index.html#about-the-author"><i class="fa fa-check"></i>About the Author</a></li>
</ul></li>
<li class="chapter" data-level="1" data-path="introduction.html"><a href="introduction.html"><i class="fa fa-check"></i><b>1</b> Introduction</a>
<ul>
<li class="chapter" data-level="1.1" data-path="introduction.html"><a href="introduction.html#why-coding-practices-matter"><i class="fa fa-check"></i><b>1.1</b> Why Coding Practices Matter</a></li>
<li class="chapter" data-level="1.2" data-path="introduction.html"><a href="introduction.html#what-this-book-covers"><i class="fa fa-check"></i><b>1.2</b> What This Book Covers</a></li>
<li class="chapter" data-level="1.3" data-path="introduction.html"><a href="introduction.html#how-to-use-this-book"><i class="fa fa-check"></i><b>1.3</b> How to Use This Book</a></li>
<li class="chapter" data-level="1.4" data-path="introduction.html"><a href="introduction.html#who-this-book-is-for"><i class="fa fa-check"></i><b>1.4</b> Who This Book Is For</a></li>
<li class="chapter" data-level="1.5" data-path="introduction.html"><a href="introduction.html#final-thoughts"><i class="fa fa-check"></i><b>1.5</b> Final Thoughts</a></li>
</ul></li>
<li class="chapter" data-level="2" data-path="naming-conventions.html"><a href="naming-conventions.html"><i class="fa fa-check"></i><b>2</b> Naming Conventions</a>
<ul>
<li class="chapter" data-level="2.1" data-path="naming-conventions.html"><a href="naming-conventions.html#naming-scripts"><i class="fa fa-check"></i><b>2.1</b> Naming Scripts</a>
<ul>
<li class="chapter" data-level="2.1.1" data-path="naming-conventions.html"><a href="naming-conventions.html#best-practices-for-script-names"><i class="fa fa-check"></i><b>2.1.1</b> Best Practices for Script Names</a></li>
<li class="chapter" data-level="2.1.2" data-path="naming-conventions.html"><a href="naming-conventions.html#example-script-names"><i class="fa fa-check"></i><b>2.1.2</b> Example Script Names</a></li>
</ul></li>
<li class="chapter" data-level="2.2" data-path="naming-conventions.html"><a href="naming-conventions.html#naming-variables"><i class="fa fa-check"></i><b>2.2</b> Naming Variables</a>
<ul>
<li class="chapter" data-level="2.2.1" data-path="naming-conventions.html"><a href="naming-conventions.html#guidelines-for-variable-names"><i class="fa fa-check"></i><b>2.2.1</b> Guidelines for Variable Names</a></li>
<li class="chapter" data-level="2.2.2" data-path="naming-conventions.html"><a href="naming-conventions.html#example-variable-names"><i class="fa fa-check"></i><b>2.2.2</b> Example Variable Names</a></li>
</ul></li>
<li class="chapter" data-level="2.3" data-path="naming-conventions.html"><a href="naming-conventions.html#naming-functions"><i class="fa fa-check"></i><b>2.3</b> Naming Functions</a>
<ul>
<li class="chapter" data-level="2.3.1" data-path="naming-conventions.html"><a href="naming-conventions.html#best-practices-for-function-names"><i class="fa fa-check"></i><b>2.3.1</b> Best Practices for Function Names</a></li>
<li class="chapter" data-level="2.3.2" data-path="naming-conventions.html"><a href="naming-conventions.html#example-function-names"><i class="fa fa-check"></i><b>2.3.2</b> Example Function Names</a></li>
</ul></li>
<li class="chapter" data-level="2.4" data-path="naming-conventions.html"><a href="naming-conventions.html#consistency-is-key"><i class="fa fa-check"></i><b>2.4</b> Consistency is Key</a></li>
<li class="chapter" data-level="2.5" data-path="naming-conventions.html"><a href="naming-conventions.html#summary"><i class="fa fa-check"></i><b>2.5</b> Summary</a></li>
</ul></li>
<li class="chapter" data-level="3" data-path="organising-scripts.html"><a href="organising-scripts.html"><i class="fa fa-check"></i><b>3</b> Organising Scripts</a>
<ul>
<li class="chapter" data-level="3.1" data-path="organising-scripts.html"><a href="organising-scripts.html#structuring-scripts"><i class="fa fa-check"></i><b>3.1</b> Structuring Scripts</a>
<ul>
<li class="chapter" data-level="3.1.1" data-path="organising-scripts.html"><a href="organising-scripts.html#logical-script-structure"><i class="fa fa-check"></i><b>3.1.1</b> Logical Script Structure</a></li>
<li class="chapter" data-level="3.1.2" data-path="organising-scripts.html"><a href="organising-scripts.html#using-functions-for-modularity"><i class="fa fa-check"></i><b>3.1.2</b> Using Functions for Modularity</a></li>
<li class="chapter" data-level="3.1.3" data-path="organising-scripts.html"><a href="organising-scripts.html#script-length"><i class="fa fa-check"></i><b>3.1.3</b> Script Length</a></li>
</ul></li>
<li class="chapter" data-level="3.2" data-path="organising-scripts.html"><a href="organising-scripts.html#organising-files-and-directories"><i class="fa fa-check"></i><b>3.2</b> Organising Files and Directories</a>
<ul>
<li class="chapter" data-level="3.2.1" data-path="organising-scripts.html"><a href="organising-scripts.html#directory-structure"><i class="fa fa-check"></i><b>3.2.1</b> Directory Structure</a></li>
<li class="chapter" data-level="3.2.2" data-path="organising-scripts.html"><a href="organising-scripts.html#data-files"><i class="fa fa-check"></i><b>3.2.2</b> Data Files</a></li>
<li class="chapter" data-level="3.2.3" data-path="organising-scripts.html"><a href="organising-scripts.html#scripts"><i class="fa fa-check"></i><b>3.2.3</b> Scripts</a></li>
<li class="chapter" data-level="3.2.4" data-path="organising-scripts.html"><a href="organising-scripts.html#output-files"><i class="fa fa-check"></i><b>3.2.4</b> Output Files</a></li>
</ul></li>
<li class="chapter" data-level="3.3" data-path="organising-scripts.html"><a href="organising-scripts.html#documentation"><i class="fa fa-check"></i><b>3.3</b> Documentation</a>
<ul>
<li class="chapter" data-level="3.3.1" data-path="organising-scripts.html"><a href="organising-scripts.html#readme-files"><i class="fa fa-check"></i><b>3.3.1</b> README Files</a></li>
<li class="chapter" data-level="3.3.2" data-path="organising-scripts.html"><a href="organising-scripts.html#inline-documentation"><i class="fa fa-check"></i><b>3.3.2</b> Inline Documentation</a></li>
</ul></li>
<li class="chapter" data-level="3.4" data-path="organising-scripts.html"><a href="organising-scripts.html#summary-1"><i class="fa fa-check"></i><b>3.4</b> Summary</a></li>
</ul></li>
<li class="chapter" data-level="4" data-path="commenting-code.html"><a href="commenting-code.html"><i class="fa fa-check"></i><b>4</b> Commenting Code</a>
<ul>
<li class="chapter" data-level="4.1" data-path="commenting-code.html"><a href="commenting-code.html#the-purpose-of-comments"><i class="fa fa-check"></i><b>4.1</b> The Purpose of Comments</a>
<ul>
<li class="chapter" data-level="4.1.1" data-path="commenting-code.html"><a href="commenting-code.html#why-comment-your-code"><i class="fa fa-check"></i><b>4.1.1</b> Why Comment Your Code?</a></li>
<li class="chapter" data-level="4.1.2" data-path="commenting-code.html"><a href="commenting-code.html#when-to-comment"><i class="fa fa-check"></i><b>4.1.2</b> When to Comment</a></li>
</ul></li>
<li class="chapter" data-level="4.2" data-path="commenting-code.html"><a href="commenting-code.html#best-practices-for-commenting"><i class="fa fa-check"></i><b>4.2</b> Best Practices for Commenting</a>
<ul>
<li class="chapter" data-level="4.2.1" data-path="commenting-code.html"><a href="commenting-code.html#writing-clear-and-concise-comments"><i class="fa fa-check"></i><b>4.2.1</b> Writing Clear and Concise Comments</a></li>
<li class="chapter" data-level="4.2.2" data-path="commenting-code.html"><a href="commenting-code.html#comment-placement"><i class="fa fa-check"></i><b>4.2.2</b> Comment Placement</a></li>
<li class="chapter" data-level="4.2.3" data-path="commenting-code.html"><a href="commenting-code.html#consistency-in-commenting"><i class="fa fa-check"></i><b>4.2.3</b> Consistency in Commenting</a></li>
</ul></li>
<li class="chapter" data-level="4.3" data-path="commenting-code.html"><a href="commenting-code.html#common-pitfalls-to-avoid"><i class="fa fa-check"></i><b>4.3</b> Common Pitfalls to Avoid</a>
<ul>
<li class="chapter" data-level="4.3.1" data-path="commenting-code.html"><a href="commenting-code.html#over-commenting"><i class="fa fa-check"></i><b>4.3.1</b> Over-Commenting</a></li>
<li class="chapter" data-level="4.3.2" data-path="commenting-code.html"><a href="commenting-code.html#commenting-out-code"><i class="fa fa-check"></i><b>4.3.2</b> Commenting Out Code</a></li>
<li class="chapter" data-level="4.3.3" data-path="commenting-code.html"><a href="commenting-code.html#vague-or-uninformative-comments"><i class="fa fa-check"></i><b>4.3.3</b> Vague or Uninformative Comments</a></li>
</ul></li>
<li class="chapter" data-level="4.4" data-path="commenting-code.html"><a href="commenting-code.html#advanced-commenting-techniques"><i class="fa fa-check"></i><b>4.4</b> Advanced Commenting Techniques</a>
<ul>
<li class="chapter" data-level="4.4.1" data-path="commenting-code.html"><a href="commenting-code.html#using-roxygen2-for-documentation"><i class="fa fa-check"></i><b>4.4.1</b> Using Roxygen2 for Documentation</a></li>
<li class="chapter" data-level="4.4.2" data-path="commenting-code.html"><a href="commenting-code.html#writing-to-do-comments"><i class="fa fa-check"></i><b>4.4.2</b> Writing “To-Do” Comments</a></li>
</ul></li>
<li class="chapter" data-level="4.5" data-path="commenting-code.html"><a href="commenting-code.html#summary-2"><i class="fa fa-check"></i><b>4.5</b> Summary</a></li>
</ul></li>
<li class="chapter" data-level="5" data-path="code-syntax-and-spacing.html"><a href="code-syntax-and-spacing.html"><i class="fa fa-check"></i><b>5</b> Code Syntax and Spacing</a>
<ul>
<li class="chapter" data-level="5.1" data-path="code-syntax-and-spacing.html"><a href="code-syntax-and-spacing.html#importance-of-consistent-syntax"><i class="fa fa-check"></i><b>5.1</b> Importance of Consistent Syntax</a>
<ul>
<li class="chapter" data-level="5.1.1" data-path="code-syntax-and-spacing.html"><a href="code-syntax-and-spacing.html#why-syntax-matters"><i class="fa fa-check"></i><b>5.1.1</b> Why Syntax Matters</a></li>
<li class="chapter" data-level="5.1.2" data-path="code-syntax-and-spacing.html"><a href="code-syntax-and-spacing.html#adopting-a-style-guide"><i class="fa fa-check"></i><b>5.1.2</b> Adopting a Style Guide</a></li>
</ul></li>
<li class="chapter" data-level="5.2" data-path="code-syntax-and-spacing.html"><a href="code-syntax-and-spacing.html#indentation"><i class="fa fa-check"></i><b>5.2</b> Indentation</a>
<ul>
<li class="chapter" data-level="5.2.1" data-path="code-syntax-and-spacing.html"><a href="code-syntax-and-spacing.html#standard-indentation-practices"><i class="fa fa-check"></i><b>5.2.1</b> Standard Indentation Practices</a></li>
<li class="chapter" data-level="5.2.2" data-path="code-syntax-and-spacing.html"><a href="code-syntax-and-spacing.html#indentation-in-functions"><i class="fa fa-check"></i><b>5.2.2</b> Indentation in Functions</a></li>
</ul></li>
<li class="chapter" data-level="5.3" data-path="code-syntax-and-spacing.html"><a href="code-syntax-and-spacing.html#spacing"><i class="fa fa-check"></i><b>5.3</b> Spacing</a>
<ul>
<li class="chapter" data-level="5.3.1" data-path="code-syntax-and-spacing.html"><a href="code-syntax-and-spacing.html#spacing-around-operators"><i class="fa fa-check"></i><b>5.3.1</b> Spacing Around Operators</a></li>
<li class="chapter" data-level="5.3.2" data-path="code-syntax-and-spacing.html"><a href="code-syntax-and-spacing.html#spacing-after-commas-and-colons"><i class="fa fa-check"></i><b>5.3.2</b> Spacing After Commas and Colons</a></li>
<li class="chapter" data-level="5.3.3" data-path="code-syntax-and-spacing.html"><a href="code-syntax-and-spacing.html#spacing-in-function-calls"><i class="fa fa-check"></i><b>5.3.3</b> Spacing in Function Calls</a></li>
<li class="chapter" data-level="5.3.4" data-path="code-syntax-and-spacing.html"><a href="code-syntax-and-spacing.html#spacing-in-conditional-statements"><i class="fa fa-check"></i><b>5.3.4</b> Spacing in Conditional Statements</a></li>
</ul></li>
<li class="chapter" data-level="5.4" data-path="code-syntax-and-spacing.html"><a href="code-syntax-and-spacing.html#line-breaks"><i class="fa fa-check"></i><b>5.4</b> Line Breaks</a>
<ul>
<li class="chapter" data-level="5.4.1" data-path="code-syntax-and-spacing.html"><a href="code-syntax-and-spacing.html#breaking-long-lines"><i class="fa fa-check"></i><b>5.4.1</b> Breaking Long Lines</a></li>
<li class="chapter" data-level="5.4.2" data-path="code-syntax-and-spacing.html"><a href="code-syntax-and-spacing.html#avoiding-deep-nesting"><i class="fa fa-check"></i><b>5.4.2</b> Avoiding Deep Nesting</a></li>
</ul></li>
<li class="chapter" data-level="5.5" data-path="code-syntax-and-spacing.html"><a href="code-syntax-and-spacing.html#aligning-code"><i class="fa fa-check"></i><b>5.5</b> Aligning Code</a>
<ul>
<li class="chapter" data-level="5.5.1" data-path="code-syntax-and-spacing.html"><a href="code-syntax-and-spacing.html#aligning-assignments"><i class="fa fa-check"></i><b>5.5.1</b> Aligning Assignments</a></li>
<li class="chapter" data-level="5.5.2" data-path="code-syntax-and-spacing.html"><a href="code-syntax-and-spacing.html#aligning-function-arguments"><i class="fa fa-check"></i><b>5.5.2</b> Aligning Function Arguments</a></li>
</ul></li>
<li class="chapter" data-level="5.6" data-path="code-syntax-and-spacing.html"><a href="code-syntax-and-spacing.html#comment-placement-and-spacing"><i class="fa fa-check"></i><b>5.6</b> Comment Placement and Spacing</a>
<ul>
<li class="chapter" data-level="5.6.1" data-path="code-syntax-and-spacing.html"><a href="code-syntax-and-spacing.html#spacing-before-comments"><i class="fa fa-check"></i><b>5.6.1</b> Spacing Before Comments</a></li>
<li class="chapter" data-level="5.6.2" data-path="code-syntax-and-spacing.html"><a href="code-syntax-and-spacing.html#block-comment-formatting"><i class="fa fa-check"></i><b>5.6.2</b> Block Comment Formatting</a></li>
</ul></li>
<li class="chapter" data-level="5.7" data-path="code-syntax-and-spacing.html"><a href="code-syntax-and-spacing.html#avoiding-common-pitfalls"><i class="fa fa-check"></i><b>5.7</b> Avoiding Common Pitfalls</a>
<ul>
<li class="chapter" data-level="5.7.1" data-path="code-syntax-and-spacing.html"><a href="code-syntax-and-spacing.html#overuse-of-blank-lines"><i class="fa fa-check"></i><b>5.7.1</b> Overuse of Blank Lines</a></li>
<li class="chapter" data-level="5.7.2" data-path="code-syntax-and-spacing.html"><a href="code-syntax-and-spacing.html#avoiding-excessive-line-length"><i class="fa fa-check"></i><b>5.7.2</b> Avoiding Excessive Line Length</a></li>
</ul></li>
<li class="chapter" data-level="5.8" data-path="code-syntax-and-spacing.html"><a href="code-syntax-and-spacing.html#summary-3"><i class="fa fa-check"></i><b>5.8</b> Summary</a></li>
</ul></li>
<li class="chapter" data-level="6" data-path="writing-functions.html"><a href="writing-functions.html"><i class="fa fa-check"></i><b>6</b> Writing Functions</a>
<ul>
<li class="chapter" data-level="6.1" data-path="writing-functions.html"><a href="writing-functions.html#the-purpose-of-functions"><i class="fa fa-check"></i><b>6.1</b> The Purpose of Functions</a>
<ul>
<li class="chapter" data-level="6.1.1" data-path="writing-functions.html"><a href="writing-functions.html#why-write-functions"><i class="fa fa-check"></i><b>6.1.1</b> Why Write Functions?</a></li>
<li class="chapter" data-level="6.1.2" data-path="writing-functions.html"><a href="writing-functions.html#when-to-write-a-function"><i class="fa fa-check"></i><b>6.1.2</b> When to Write a Function</a></li>
</ul></li>
<li class="chapter" data-level="6.2" data-path="writing-functions.html"><a href="writing-functions.html#structure-of-a-function"><i class="fa fa-check"></i><b>6.2</b> Structure of a Function</a>
<ul>
<li class="chapter" data-level="6.2.1" data-path="writing-functions.html"><a href="writing-functions.html#basic-function-structure"><i class="fa fa-check"></i><b>6.2.1</b> Basic Function Structure</a></li>
<li class="chapter" data-level="6.2.2" data-path="writing-functions.html"><a href="writing-functions.html#naming-conventions-1"><i class="fa fa-check"></i><b>6.2.2</b> Naming Conventions</a></li>
<li class="chapter" data-level="6.2.3" data-path="writing-functions.html"><a href="writing-functions.html#function-arguments"><i class="fa fa-check"></i><b>6.2.3</b> Function Arguments</a></li>
<li class="chapter" data-level="6.2.4" data-path="writing-functions.html"><a href="writing-functions.html#function-body"><i class="fa fa-check"></i><b>6.2.4</b> Function Body</a></li>
<li class="chapter" data-level="6.2.5" data-path="writing-functions.html"><a href="writing-functions.html#return-values"><i class="fa fa-check"></i><b>6.2.5</b> Return Values</a></li>
</ul></li>
<li class="chapter" data-level="6.3" data-path="writing-functions.html"><a href="writing-functions.html#documentation-and-commenting"><i class="fa fa-check"></i><b>6.3</b> Documentation and Commenting</a>
<ul>
<li class="chapter" data-level="6.3.1" data-path="writing-functions.html"><a href="writing-functions.html#documenting-functions-with-roxygen2"><i class="fa fa-check"></i><b>6.3.1</b> Documenting Functions with Roxygen2</a></li>
<li class="chapter" data-level="6.3.2" data-path="writing-functions.html"><a href="writing-functions.html#commenting-inside-functions"><i class="fa fa-check"></i><b>6.3.2</b> Commenting Inside Functions</a></li>
</ul></li>
<li class="chapter" data-level="6.4" data-path="writing-functions.html"><a href="writing-functions.html#testing-functions"><i class="fa fa-check"></i><b>6.4</b> Testing Functions</a>
<ul>
<li class="chapter" data-level="6.4.1" data-path="writing-functions.html"><a href="writing-functions.html#why-test-functions"><i class="fa fa-check"></i><b>6.4.1</b> Why Test Functions?</a></li>
<li class="chapter" data-level="6.4.2" data-path="writing-functions.html"><a href="writing-functions.html#writing-simple-tests"><i class="fa fa-check"></i><b>6.4.2</b> Writing Simple Tests</a></li>
<li class="chapter" data-level="6.4.3" data-path="writing-functions.html"><a href="writing-functions.html#automated-testing-with-testthat"><i class="fa fa-check"></i><b>6.4.3</b> Automated Testing with <code>testthat</code></a></li>
</ul></li>
<li class="chapter" data-level="6.5" data-path="writing-functions.html"><a href="writing-functions.html#advanced-function-techniques"><i class="fa fa-check"></i><b>6.5</b> Advanced Function Techniques</a>
<ul>
<li class="chapter" data-level="6.5.1" data-path="writing-functions.html"><a href="writing-functions.html#function-factories"><i class="fa fa-check"></i><b>6.5.1</b> Function Factories</a></li>
<li class="chapter" data-level="6.5.2" data-path="writing-functions.html"><a href="writing-functions.html#closures"><i class="fa fa-check"></i><b>6.5.2</b> Closures</a></li>
<li class="chapter" data-level="6.5.3" data-path="writing-functions.html"><a href="writing-functions.html#vectorised-functions"><i class="fa fa-check"></i><b>6.5.3</b> Vectorised Functions</a></li>
<li class="chapter" data-level="6.5.4" data-path="writing-functions.html"><a href="writing-functions.html#anonymous-functions"><i class="fa fa-check"></i><b>6.5.4</b> Anonymous Functions</a></li>
</ul></li>
<li class="chapter" data-level="6.6" data-path="writing-functions.html"><a href="writing-functions.html#avoiding-common-pitfalls-in-function-writing"><i class="fa fa-check"></i><b>6.6</b> Avoiding Common Pitfalls in Function Writing</a>
<ul>
<li class="chapter" data-level="6.6.1" data-path="writing-functions.html"><a href="writing-functions.html#overloading-functions"><i class="fa fa-check"></i><b>6.6.1</b> Overloading Functions</a></li>
<li class="chapter" data-level="6.6.2" data-path="writing-functions.html"><a href="writing-functions.html#handling-errors-gracefully"><i class="fa fa-check"></i><b>6.6.2</b> Handling Errors Gracefully</a></li>
<li class="chapter" data-level="6.6.3" data-path="writing-functions.html"><a href="writing-functions.html#avoiding-side-effects"><i class="fa fa-check"></i><b>6.6.3</b> Avoiding Side Effects</a></li>
</ul></li>
<li class="chapter" data-level="6.7" data-path="writing-functions.html"><a href="writing-functions.html#summary-4"><i class="fa fa-check"></i><b>6.7</b> Summary</a></li>
</ul></li>
<li class="chapter" data-level="7" data-path="error-handling.html"><a href="error-handling.html"><i class="fa fa-check"></i><b>7</b> Error Handling</a>
<ul>
<li class="chapter" data-level="7.1" data-path="error-handling.html"><a href="error-handling.html#introduction-to-error-handling"><i class="fa fa-check"></i><b>7.1</b> Introduction to Error Handling</a>
<ul>
<li class="chapter" data-level="7.1.1" data-path="error-handling.html"><a href="error-handling.html#what-is-error-handling"><i class="fa fa-check"></i><b>7.1.1</b> What is Error Handling?</a></li>
<li class="chapter" data-level="7.1.2" data-path="error-handling.html"><a href="error-handling.html#types-of-errors-in-r"><i class="fa fa-check"></i><b>7.1.2</b> Types of Errors in R</a></li>
</ul></li>
<li class="chapter" data-level="7.2" data-path="error-handling.html"><a href="error-handling.html#basic-error-handling-with-try-and-trycatch"><i class="fa fa-check"></i><b>7.2</b> Basic Error Handling with <code>try</code> and <code>tryCatch</code></a>
<ul>
<li class="chapter" data-level="7.2.1" data-path="error-handling.html"><a href="error-handling.html#using-try"><i class="fa fa-check"></i><b>7.2.1</b> Using <code>try</code></a></li>
<li class="chapter" data-level="7.2.2" data-path="error-handling.html"><a href="error-handling.html#using-trycatch"><i class="fa fa-check"></i><b>7.2.2</b> Using <code>tryCatch</code></a></li>
<li class="chapter" data-level="7.2.3" data-path="error-handling.html"><a href="error-handling.html#returning-values-from-trycatch"><i class="fa fa-check"></i><b>7.2.3</b> Returning Values from <code>tryCatch</code></a></li>
</ul></li>
<li class="chapter" data-level="7.3" data-path="error-handling.html"><a href="error-handling.html#custom-error-messages-with-stop-warning-and-message"><i class="fa fa-check"></i><b>7.3</b> Custom Error Messages with <code>stop</code>, <code>warning</code>, and <code>message</code></a>
<ul>
<li class="chapter" data-level="7.3.1" data-path="error-handling.html"><a href="error-handling.html#using-stop-for-critical-errors"><i class="fa fa-check"></i><b>7.3.1</b> Using <code>stop</code> for Critical Errors</a></li>
<li class="chapter" data-level="7.3.2" data-path="error-handling.html"><a href="error-handling.html#using-warning-for-non-critical-issues"><i class="fa fa-check"></i><b>7.3.2</b> Using <code>warning</code> for Non-Critical Issues</a></li>
<li class="chapter" data-level="7.3.3" data-path="error-handling.html"><a href="error-handling.html#using-message-for-informational-messages"><i class="fa fa-check"></i><b>7.3.3</b> Using <code>message</code> for Informational Messages</a></li>
</ul></li>
<li class="chapter" data-level="7.4" data-path="error-handling.html"><a href="error-handling.html#defensive-programming"><i class="fa fa-check"></i><b>7.4</b> Defensive Programming</a>
<ul>
<li class="chapter" data-level="7.4.1" data-path="error-handling.html"><a href="error-handling.html#input-validation"><i class="fa fa-check"></i><b>7.4.1</b> Input Validation</a></li>
<li class="chapter" data-level="7.4.2" data-path="error-handling.html"><a href="error-handling.html#asserting-conditions"><i class="fa fa-check"></i><b>7.4.2</b> Asserting Conditions</a></li>
<li class="chapter" data-level="7.4.3" data-path="error-handling.html"><a href="error-handling.html#handling-edge-cases"><i class="fa fa-check"></i><b>7.4.3</b> Handling Edge Cases</a></li>
</ul></li>
<li class="chapter" data-level="7.5" data-path="error-handling.html"><a href="error-handling.html#best-practices-for-error-handling"><i class="fa fa-check"></i><b>7.5</b> Best Practices for Error Handling</a>
<ul>
<li class="chapter" data-level="7.5.1" data-path="error-handling.html"><a href="error-handling.html#provide-clear-and-informative-messages"><i class="fa fa-check"></i><b>7.5.1</b> Provide Clear and Informative Messages</a></li>
<li class="chapter" data-level="7.5.2" data-path="error-handling.html"><a href="error-handling.html#use-trycatch-for-anticipated-errors"><i class="fa fa-check"></i><b>7.5.2</b> Use <code>tryCatch</code> for Anticipated Errors</a></li>
<li class="chapter" data-level="7.5.3" data-path="error-handling.html"><a href="error-handling.html#log-errors-in-production-code"><i class="fa fa-check"></i><b>7.5.3</b> Log Errors in Production Code</a></li>
<li class="chapter" data-level="7.5.4" data-path="error-handling.html"><a href="error-handling.html#test-error-handling"><i class="fa fa-check"></i><b>7.5.4</b> Test Error Handling</a></li>
</ul></li>
<li class="chapter" data-level="7.6" data-path="error-handling.html"><a href="error-handling.html#summary-5"><i class="fa fa-check"></i><b>7.6</b> Summary</a></li>
</ul></li>
<li class="chapter" data-level="8" data-path="version-control-with-git.html"><a href="version-control-with-git.html"><i class="fa fa-check"></i><b>8</b> Version Control with Git</a>
<ul>
<li class="chapter" data-level="8.1" data-path="version-control-with-git.html"><a href="version-control-with-git.html#introduction-to-git"><i class="fa fa-check"></i><b>8.1</b> Introduction to Git</a>
<ul>
<li class="chapter" data-level="8.1.1" data-path="version-control-with-git.html"><a href="version-control-with-git.html#benefits-of-using-git"><i class="fa fa-check"></i><b>8.1.1</b> Benefits of Using Git</a></li>
</ul></li>
<li class="chapter" data-level="8.2" data-path="version-control-with-git.html"><a href="version-control-with-git.html#setting-up-git"><i class="fa fa-check"></i><b>8.2</b> Setting Up Git</a>
<ul>
<li class="chapter" data-level="8.2.1" data-path="version-control-with-git.html"><a href="version-control-with-git.html#installing-git"><i class="fa fa-check"></i><b>8.2.1</b> Installing Git</a></li>
<li class="chapter" data-level="8.2.2" data-path="version-control-with-git.html"><a href="version-control-with-git.html#configuring-git"><i class="fa fa-check"></i><b>8.2.2</b> Configuring Git</a></li>
</ul></li>
<li class="chapter" data-level="8.3" data-path="version-control-with-git.html"><a href="version-control-with-git.html#basic-git-workflow"><i class="fa fa-check"></i><b>8.3</b> Basic Git Workflow</a>
<ul>
<li class="chapter" data-level="8.3.1" data-path="version-control-with-git.html"><a href="version-control-with-git.html#initialising-a-repository"><i class="fa fa-check"></i><b>8.3.1</b> Initialising a Repository</a></li>
<li class="chapter" data-level="8.3.2" data-path="version-control-with-git.html"><a href="version-control-with-git.html#staging-and-committing-changes"><i class="fa fa-check"></i><b>8.3.2</b> Staging and Committing Changes</a></li>
<li class="chapter" data-level="8.3.3" data-path="version-control-with-git.html"><a href="version-control-with-git.html#viewing-repository-status"><i class="fa fa-check"></i><b>8.3.3</b> Viewing Repository Status</a></li>
<li class="chapter" data-level="8.3.4" data-path="version-control-with-git.html"><a href="version-control-with-git.html#viewing-commit-history"><i class="fa fa-check"></i><b>8.3.4</b> Viewing Commit History</a></li>
</ul></li>
<li class="chapter" data-level="8.4" data-path="version-control-with-git.html"><a href="version-control-with-git.html#branching-and-merging"><i class="fa fa-check"></i><b>8.4</b> Branching and Merging</a>
<ul>
<li class="chapter" data-level="8.4.1" data-path="version-control-with-git.html"><a href="version-control-with-git.html#creating-and-switching-branches"><i class="fa fa-check"></i><b>8.4.1</b> Creating and Switching Branches</a></li>
<li class="chapter" data-level="8.4.2" data-path="version-control-with-git.html"><a href="version-control-with-git.html#merging-branches"><i class="fa fa-check"></i><b>8.4.2</b> Merging Branches</a></li>
<li class="chapter" data-level="8.4.3" data-path="version-control-with-git.html"><a href="version-control-with-git.html#resolving-merge-conflicts"><i class="fa fa-check"></i><b>8.4.3</b> Resolving Merge Conflicts</a></li>
</ul></li>
<li class="chapter" data-level="8.5" data-path="version-control-with-git.html"><a href="version-control-with-git.html#working-with-remote-repositories"><i class="fa fa-check"></i><b>8.5</b> Working with Remote Repositories</a>
<ul>
<li class="chapter" data-level="8.5.1" data-path="version-control-with-git.html"><a href="version-control-with-git.html#cloning-a-repository"><i class="fa fa-check"></i><b>8.5.1</b> Cloning a Repository</a></li>
<li class="chapter" data-level="8.5.2" data-path="version-control-with-git.html"><a href="version-control-with-git.html#before-starting-work-ensure-your-local-repository-is-up-to-date-by-pulling-the-latest-changes"><i class="fa fa-check"></i><b>8.5.2</b> Before starting work, ensure your local repository is up to date by pulling the latest changes:</a></li>
<li class="chapter" data-level="8.5.3" data-path="version-control-with-git.html"><a href="version-control-with-git.html#pushing-changes"><i class="fa fa-check"></i><b>8.5.3</b> Pushing Changes</a></li>
</ul></li>
<li class="chapter" data-level="8.6" data-path="version-control-with-git.html"><a href="version-control-with-git.html#advanced-git-features"><i class="fa fa-check"></i><b>8.6</b> Advanced Git Features</a>
<ul>
<li class="chapter" data-level="8.6.1" data-path="version-control-with-git.html"><a href="version-control-with-git.html#stashing-changes"><i class="fa fa-check"></i><b>8.6.1</b> Stashing Changes</a></li>
<li class="chapter" data-level="8.6.2" data-path="version-control-with-git.html"><a href="version-control-with-git.html#rebasing"><i class="fa fa-check"></i><b>8.6.2</b> Rebasing</a></li>
<li class="chapter" data-level="8.6.3" data-path="version-control-with-git.html"><a href="version-control-with-git.html#tags"><i class="fa fa-check"></i><b>8.6.3</b> Tags</a></li>
</ul></li>
<li class="chapter" data-level="8.7" data-path="version-control-with-git.html"><a href="version-control-with-git.html#git-in-rstudio"><i class="fa fa-check"></i><b>8.7</b> Git in RStudio</a>
<ul>
<li class="chapter" data-level="8.7.1" data-path="version-control-with-git.html"><a href="version-control-with-git.html#setting-up-git-in-rstudio"><i class="fa fa-check"></i><b>8.7.1</b> Setting Up Git in RStudio</a></li>
<li class="chapter" data-level="8.7.2" data-path="version-control-with-git.html"><a href="version-control-with-git.html#using-git-in-rstudio"><i class="fa fa-check"></i><b>8.7.2</b> Using Git in RStudio</a></li>
</ul></li>
<li class="chapter" data-level="8.8" data-path="version-control-with-git.html"><a href="version-control-with-git.html#best-practices-for-using-git"><i class="fa fa-check"></i><b>8.8</b> Best Practices for Using Git</a></li>
<li class="chapter" data-level="8.9" data-path="version-control-with-git.html"><a href="version-control-with-git.html#summary-6"><i class="fa fa-check"></i><b>8.9</b> Summary</a></li>
</ul></li>
<li class="chapter" data-level="9" data-path="reproducibility-and-documentation.html"><a href="reproducibility-and-documentation.html"><i class="fa fa-check"></i><b>9</b> Reproducibility and Documentation</a>
<ul>
<li class="chapter" data-level="9.1" data-path="reproducibility-and-documentation.html"><a href="reproducibility-and-documentation.html#introduction-to-reproducibility"><i class="fa fa-check"></i><b>9.1</b> Introduction to Reproducibility</a>
<ul>
<li class="chapter" data-level="9.1.1" data-path="reproducibility-and-documentation.html"><a href="reproducibility-and-documentation.html#what-is-reproducibility"><i class="fa fa-check"></i><b>9.1.1</b> What is Reproducibility?</a></li>
<li class="chapter" data-level="9.1.2" data-path="reproducibility-and-documentation.html"><a href="reproducibility-and-documentation.html#challenges-to-reproducibility"><i class="fa fa-check"></i><b>9.1.2</b> Challenges to Reproducibility</a></li>
</ul></li>
<li class="chapter" data-level="9.2" data-path="reproducibility-and-documentation.html"><a href="reproducibility-and-documentation.html#setting-up-a-reproducible-environment"><i class="fa fa-check"></i><b>9.2</b> Setting Up a Reproducible Environment</a>
<ul>
<li class="chapter" data-level="9.2.1" data-path="reproducibility-and-documentation.html"><a href="reproducibility-and-documentation.html#managing-r-and-package-versions"><i class="fa fa-check"></i><b>9.2.1</b> Managing R and Package Versions</a></li>
<li class="chapter" data-level="9.2.2" data-path="reproducibility-and-documentation.html"><a href="reproducibility-and-documentation.html#using-rmarkdown-for-reproducible-reports"><i class="fa fa-check"></i><b>9.2.2</b> Using RMarkdown for Reproducible Reports</a></li>
<li class="chapter" data-level="9.2.3" data-path="reproducibility-and-documentation.html"><a href="reproducibility-and-documentation.html#version-control-with-git-1"><i class="fa fa-check"></i><b>9.2.3</b> Version Control with Git</a></li>
</ul></li>
<li class="chapter" data-level="9.3" data-path="reproducibility-and-documentation.html"><a href="reproducibility-and-documentation.html#sharing-your-work"><i class="fa fa-check"></i><b>9.3</b> Sharing Your Work</a>
<ul>
<li class="chapter" data-level="9.3.1" data-path="reproducibility-and-documentation.html"><a href="reproducibility-and-documentation.html#sharing-code-and-data"><i class="fa fa-check"></i><b>9.3.1</b> Sharing Code and Data</a></li>
<li class="chapter" data-level="9.3.2" data-path="reproducibility-and-documentation.html"><a href="reproducibility-and-documentation.html#creating-reproducible-examples"><i class="fa fa-check"></i><b>9.3.2</b> Creating Reproducible Examples</a></li>
</ul></li>
<li class="chapter" data-level="9.4" data-path="reproducibility-and-documentation.html"><a href="reproducibility-and-documentation.html#documentation-for-reproducibility"><i class="fa fa-check"></i><b>9.4</b> Documentation for Reproducibility</a>
<ul>
<li class="chapter" data-level="9.4.1" data-path="reproducibility-and-documentation.html"><a href="reproducibility-and-documentation.html#documenting-data"><i class="fa fa-check"></i><b>9.4.1</b> Documenting Data</a></li>
<li class="chapter" data-level="9.4.2" data-path="reproducibility-and-documentation.html"><a href="reproducibility-and-documentation.html#writing-a-readme-file"><i class="fa fa-check"></i><b>9.4.2</b> Writing a README File</a></li>
<li class="chapter" data-level="9.4.3" data-path="reproducibility-and-documentation.html"><a href="reproducibility-and-documentation.html#creating-a-reproducibility-checklist"><i class="fa fa-check"></i><b>9.4.3</b> Creating a Reproducibility Checklist</a></li>
</ul></li>
<li class="chapter" data-level="9.5" data-path="reproducibility-and-documentation.html"><a href="reproducibility-and-documentation.html#case-study-reproducible-analysis-in-r"><i class="fa fa-check"></i><b>9.5</b> Case Study: Reproducible Analysis in R</a>
<ul>
<li class="chapter" data-level="9.5.1" data-path="reproducibility-and-documentation.html"><a href="reproducibility-and-documentation.html#overview"><i class="fa fa-check"></i><b>9.5.1</b> Overview</a></li>
<li class="chapter" data-level="9.5.2" data-path="reproducibility-and-documentation.html"><a href="reproducibility-and-documentation.html#setting-up-the-project"><i class="fa fa-check"></i><b>9.5.2</b> Setting Up the Project</a></li>
<li class="chapter" data-level="9.5.3" data-path="reproducibility-and-documentation.html"><a href="reproducibility-and-documentation.html#documenting-the-analysis"><i class="fa fa-check"></i><b>9.5.3</b> Documenting the Analysis</a></li>
<li class="chapter" data-level="9.5.4" data-path="reproducibility-and-documentation.html"><a href="reproducibility-and-documentation.html#sharing-the-project"><i class="fa fa-check"></i><b>9.5.4</b> Sharing the Project</a></li>
<li class="chapter" data-level="9.5.5" data-path="reproducibility-and-documentation.html"><a href="reproducibility-and-documentation.html#running-the-analysis"><i class="fa fa-check"></i><b>9.5.5</b> Running the Analysis</a></li>
</ul></li>
<li class="chapter" data-level="9.6" data-path="reproducibility-and-documentation.html"><a href="reproducibility-and-documentation.html#summary-7"><i class="fa fa-check"></i><b>9.6</b> Summary</a></li>
</ul></li>
<li class="chapter" data-level="10" data-path="conclusion.html"><a href="conclusion.html"><i class="fa fa-check"></i><b>10</b> Conclusion</a>
<ul>
<li class="chapter" data-level="10.1" data-path="conclusion.html"><a href="conclusion.html#recap-of-key-concepts"><i class="fa fa-check"></i><b>10.1</b> Recap of Key Concepts</a>
<ul>
<li class="chapter" data-level="10.1.1" data-path="conclusion.html"><a href="conclusion.html#introduction-1"><i class="fa fa-check"></i><b>10.1.1</b> Introduction</a></li>
<li class="chapter" data-level="10.1.2" data-path="conclusion.html"><a href="conclusion.html#naming-conventions-2"><i class="fa fa-check"></i><b>10.1.2</b> Naming Conventions</a></li>
<li class="chapter" data-level="10.1.3" data-path="conclusion.html"><a href="conclusion.html#organising-scripts-1"><i class="fa fa-check"></i><b>10.1.3</b> Organising Scripts</a></li>
<li class="chapter" data-level="10.1.4" data-path="conclusion.html"><a href="conclusion.html#commenting-code-1"><i class="fa fa-check"></i><b>10.1.4</b> Commenting Code</a></li>
<li class="chapter" data-level="10.1.5" data-path="conclusion.html"><a href="conclusion.html#syntax-and-spacing"><i class="fa fa-check"></i><b>10.1.5</b> Syntax and Spacing</a></li>
<li class="chapter" data-level="10.1.6" data-path="conclusion.html"><a href="conclusion.html#writing-functions-1"><i class="fa fa-check"></i><b>10.1.6</b> Writing Functions</a></li>
<li class="chapter" data-level="10.1.7" data-path="conclusion.html"><a href="conclusion.html#error-handling-1"><i class="fa fa-check"></i><b>10.1.7</b> Error Handling</a></li>
<li class="chapter" data-level="10.1.8" data-path="conclusion.html"><a href="conclusion.html#version-control-with-git-2"><i class="fa fa-check"></i><b>10.1.8</b> Version Control with Git</a></li>
<li class="chapter" data-level="10.1.9" data-path="conclusion.html"><a href="conclusion.html#reproducibility-and-documentation-1"><i class="fa fa-check"></i><b>10.1.9</b> Reproducibility and Documentation</a></li>
</ul></li>
<li class="chapter" data-level="10.2" data-path="conclusion.html"><a href="conclusion.html#the-importance-of-adopting-best-practices"><i class="fa fa-check"></i><b>10.2</b> The Importance of Adopting Best Practices</a></li>
<li class="chapter" data-level="10.3" data-path="conclusion.html"><a href="conclusion.html#moving-forward"><i class="fa fa-check"></i><b>10.3</b> Moving Forward</a></li>
<li class="chapter" data-level="10.4" data-path="conclusion.html"><a href="conclusion.html#final-thoughts-1"><i class="fa fa-check"></i><b>10.4</b> Final Thoughts</a></li>
</ul></li>
<li class="divider"></li>
<li><a href="https://github.com/rstudio/bookdown" target="blank">Published with bookdown</a></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="./">Best Coding Practices in R</a>
</h1>
</div>
<div class="page-wrapper" tabindex="-1" role="main">
<div class="page-inner">
<section class="normal" id="section-">
<div id="introduction" class="section level1 hasAnchor" number="1">
<h1><span class="header-section-number">1</span> Introduction<a href="introduction.html#introduction" class="anchor-section" aria-label="Anchor link to header"></a></h1>
<p>Coding practices are essential for writing clean, efficient, and maintainable code, especially in a language like R, which is widely used for data analysis, statistical modelling, and visualisation. Good coding practices not only improve the readability of your code but also make it easier to debug, extend, and collaborate with others.</p>
<p>In this book, we will explore best practices for coding in R, covering topics such as naming conventions, organising scripts, commenting, syntax spacing, and more. Whether you are a beginner looking to establish strong foundations or an experienced R programmer aiming to refine your coding style, this guide will provide you with the tools and knowledge you need to write high-quality R code.</p>
<div id="why-coding-practices-matter" class="section level2 hasAnchor" number="1.1">
<h2><span class="header-section-number">1.1</span> Why Coding Practices Matter<a href="introduction.html#why-coding-practices-matter" class="anchor-section" aria-label="Anchor link to header"></a></h2>
<p>When working on R projects, especially in collaborative environments, it’s crucial to write code that is:</p>
<ul>
<li><strong>Readable:</strong> Your code should be easy to understand for others (and your future self). Clear and consistent code reduces the cognitive load required to interpret it.</li>
<li><strong>Maintainable:</strong> Code should be written in a way that makes it easy to update, fix, and extend. This is especially important in long-term projects or when handing off your code to others.</li>
<li><strong>Reusable:</strong> Good practices encourage writing modular and reusable code. This not only saves time but also reduces errors by avoiding duplication.</li>
<li><strong>Collaborative:</strong> In team settings, standardised coding practices ensure that everyone writes code in a similar style, making it easier to integrate and review each other’s work.</li>
</ul>
</div>
<div id="what-this-book-covers" class="section level2 hasAnchor" number="1.2">
<h2><span class="header-section-number">1.2</span> What This Book Covers<a href="introduction.html#what-this-book-covers" class="anchor-section" aria-label="Anchor link to header"></a></h2>
<p>This book is organised into several chapters, each focusing on a specific aspect of coding practices in R. Here’s an overview of what you can expect:</p>
<ol start="2" style="list-style-type: decimal">
<li><p><strong>Naming Conventions:</strong> Best practices for naming scripts, variables, and functions in a consistent and descriptive manner.</p></li>
<li><p><strong>Organising Scripts:</strong> Strategies for structuring your scripts and projects, including how to organise files and directories.</p></li>
<li><p><strong>Commenting Code:</strong> Guidelines on how to effectively comment your code to enhance understanding and maintainability.</p></li>
<li><p><strong>Code Syntax and Spacing:</strong> Rules for formatting your code, including spacing, indentation, and layout to improve readability.</p></li>
<li><p><strong>Writing Functions:</strong> Best practices for creating functions that are clear, efficient, and easy to test and debug.</p></li>
<li><p><strong>Error Handling:</strong> Techniques for managing and logging errors in your R code to ensure robustness and reliability.</p></li>
<li><p><strong>Version Control with Git:</strong> Introduction to using Git for version control, with a focus on best practices for managing R projects.</p></li>
<li><p><strong>Reproducibility and Documentation:</strong> Ensuring that your R code and analyses are reproducible and well-documented.</p></li>
</ol>
</div>
<div id="how-to-use-this-book" class="section level2 hasAnchor" number="1.3">
<h2><span class="header-section-number">1.3</span> How to Use This Book<a href="introduction.html#how-to-use-this-book" class="anchor-section" aria-label="Anchor link to header"></a></h2>
<p>Each chapter is designed to be self-contained, allowing you to focus on the topics most relevant to your needs. However, we recommend reading the book in order, as many of the concepts build on each other. Throughout the book, you will find examples, code snippets, and exercises to help reinforce the material.</p>
</div>
<div id="who-this-book-is-for" class="section level2 hasAnchor" number="1.4">
<h2><span class="header-section-number">1.4</span> Who This Book Is For<a href="introduction.html#who-this-book-is-for" class="anchor-section" aria-label="Anchor link to header"></a></h2>
<p>This book is intended for a wide audience, including:</p>
<ul>
<li><strong>Beginner R Programmers:</strong> If you are new to R, this book will help you establish good habits from the start.</li>
<li><strong>Experienced R Programmers:</strong> If you have experience in R but want to refine your coding practices, this book offers advanced tips and best practices.</li>
<li><strong>Data Scientists and Analysts:</strong> Professionals who use R for data analysis and want to improve the quality and maintainability of their code.</li>
<li><strong>Students and Researchers:</strong> Those who are using R for academic research and need to ensure that their code is clean, reproducible, and well-documented.</li>
</ul>
</div>
<div id="final-thoughts" class="section level2 hasAnchor" number="1.5">
<h2><span class="header-section-number">1.5</span> Final Thoughts<a href="introduction.html#final-thoughts" class="anchor-section" aria-label="Anchor link to header"></a></h2>
<p>By the end of this book, you will have a solid understanding of how to write clean, efficient, and maintainable R code. These best practices will not only enhance your productivity but also ensure that your code is robust and reliable, whether you are working on a personal project or collaborating with others.</p>
<p>Let’s begin our journey towards better R coding practices!</p>
</div>
</div>
</section>
</div>
</div>
</div>
<a href="index.html" class="navigation navigation-prev " aria-label="Previous page"><i class="fa fa-angle-left"></i></a>
<a href="naming-conventions.html" class="navigation navigation-next " aria-label="Next page"><i class="fa fa-angle-right"></i></a>
</div>
</div>
<script src="libs/gitbook-2.6.7/js/app.min.js"></script>
<script src="libs/gitbook-2.6.7/js/clipboard.min.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-search.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-sharing.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-fontsettings.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-bookdown.js"></script>
<script src="libs/gitbook-2.6.7/js/jquery.highlight.js"></script>
<script src="libs/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,
"whatsapp": false,
"all": ["facebook", "twitter", "linkedin", "weibo", "instapaper"]
},
"fontsettings": {
"theme": "white",
"family": "sans",
"size": 2
},
"edit": {
"link": "https://github.com/USERNAME/REPO/edit/BRANCH/01-intro.Rmd",
"text": "Edit"
},
"history": {
"link": null,
"text": null
},
"view": {
"link": null,
"text": null
},
"download": ["_main.pdf", "_main.epub"],
"search": {
"engine": "fuse",
"options": null
},
"toc": {
"collapse": "subsection"
}
});
});
</script>
</body>
</html>