-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.tex
6426 lines (5273 loc) · 174 KB
/
index.tex
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
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
% Options for packages loaded elsewhere
\PassOptionsToPackage{unicode}{hyperref}
\PassOptionsToPackage{hyphens}{url}
\PassOptionsToPackage{dvipsnames,svgnames,x11names}{xcolor}
%
\documentclass[
letterpaper,
DIV=11,
numbers=noendperiod]{scrreprt}
\usepackage{amsmath,amssymb}
\usepackage{iftex}
\ifPDFTeX
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{textcomp} % provide euro and other symbols
\else % if luatex or xetex
\usepackage{unicode-math}
\defaultfontfeatures{Scale=MatchLowercase}
\defaultfontfeatures[\rmfamily]{Ligatures=TeX,Scale=1}
\fi
\usepackage{lmodern}
\ifPDFTeX\else
% xetex/luatex font selection
\fi
% Use upquote if available, for straight quotes in verbatim environments
\IfFileExists{upquote.sty}{\usepackage{upquote}}{}
\IfFileExists{microtype.sty}{% use microtype if available
\usepackage[]{microtype}
\UseMicrotypeSet[protrusion]{basicmath} % disable protrusion for tt fonts
}{}
\makeatletter
\@ifundefined{KOMAClassName}{% if non-KOMA class
\IfFileExists{parskip.sty}{%
\usepackage{parskip}
}{% else
\setlength{\parindent}{0pt}
\setlength{\parskip}{6pt plus 2pt minus 1pt}}
}{% if KOMA class
\KOMAoptions{parskip=half}}
\makeatother
\usepackage{xcolor}
\setlength{\emergencystretch}{3em} % prevent overfull lines
\setcounter{secnumdepth}{4}
% Make \paragraph and \subparagraph free-standing
\ifx\paragraph\undefined\else
\let\oldparagraph\paragraph
\renewcommand{\paragraph}[1]{\oldparagraph{#1}\mbox{}}
\fi
\ifx\subparagraph\undefined\else
\let\oldsubparagraph\subparagraph
\renewcommand{\subparagraph}[1]{\oldsubparagraph{#1}\mbox{}}
\fi
\usepackage{color}
\usepackage{fancyvrb}
\newcommand{\VerbBar}{|}
\newcommand{\VERB}{\Verb[commandchars=\\\{\}]}
\DefineVerbatimEnvironment{Highlighting}{Verbatim}{commandchars=\\\{\}}
% Add ',fontsize=\small' for more characters per line
\newenvironment{Shaded}{}{}
\newcommand{\AlertTok}[1]{\textcolor[rgb]{1.00,0.33,0.33}{\textbf{#1}}}
\newcommand{\AnnotationTok}[1]{\textcolor[rgb]{0.42,0.45,0.49}{#1}}
\newcommand{\AttributeTok}[1]{\textcolor[rgb]{0.84,0.23,0.29}{#1}}
\newcommand{\BaseNTok}[1]{\textcolor[rgb]{0.00,0.36,0.77}{#1}}
\newcommand{\BuiltInTok}[1]{\textcolor[rgb]{0.84,0.23,0.29}{#1}}
\newcommand{\CharTok}[1]{\textcolor[rgb]{0.01,0.18,0.38}{#1}}
\newcommand{\CommentTok}[1]{\textcolor[rgb]{0.42,0.45,0.49}{#1}}
\newcommand{\CommentVarTok}[1]{\textcolor[rgb]{0.42,0.45,0.49}{#1}}
\newcommand{\ConstantTok}[1]{\textcolor[rgb]{0.00,0.36,0.77}{#1}}
\newcommand{\ControlFlowTok}[1]{\textcolor[rgb]{0.84,0.23,0.29}{#1}}
\newcommand{\DataTypeTok}[1]{\textcolor[rgb]{0.84,0.23,0.29}{#1}}
\newcommand{\DecValTok}[1]{\textcolor[rgb]{0.00,0.36,0.77}{#1}}
\newcommand{\DocumentationTok}[1]{\textcolor[rgb]{0.42,0.45,0.49}{#1}}
\newcommand{\ErrorTok}[1]{\textcolor[rgb]{1.00,0.33,0.33}{\underline{#1}}}
\newcommand{\ExtensionTok}[1]{\textcolor[rgb]{0.84,0.23,0.29}{\textbf{#1}}}
\newcommand{\FloatTok}[1]{\textcolor[rgb]{0.00,0.36,0.77}{#1}}
\newcommand{\FunctionTok}[1]{\textcolor[rgb]{0.44,0.26,0.76}{#1}}
\newcommand{\ImportTok}[1]{\textcolor[rgb]{0.01,0.18,0.38}{#1}}
\newcommand{\InformationTok}[1]{\textcolor[rgb]{0.42,0.45,0.49}{#1}}
\newcommand{\KeywordTok}[1]{\textcolor[rgb]{0.84,0.23,0.29}{#1}}
\newcommand{\NormalTok}[1]{\textcolor[rgb]{0.14,0.16,0.18}{#1}}
\newcommand{\OperatorTok}[1]{\textcolor[rgb]{0.14,0.16,0.18}{#1}}
\newcommand{\OtherTok}[1]{\textcolor[rgb]{0.44,0.26,0.76}{#1}}
\newcommand{\PreprocessorTok}[1]{\textcolor[rgb]{0.84,0.23,0.29}{#1}}
\newcommand{\RegionMarkerTok}[1]{\textcolor[rgb]{0.42,0.45,0.49}{#1}}
\newcommand{\SpecialCharTok}[1]{\textcolor[rgb]{0.00,0.36,0.77}{#1}}
\newcommand{\SpecialStringTok}[1]{\textcolor[rgb]{0.01,0.18,0.38}{#1}}
\newcommand{\StringTok}[1]{\textcolor[rgb]{0.01,0.18,0.38}{#1}}
\newcommand{\VariableTok}[1]{\textcolor[rgb]{0.89,0.38,0.04}{#1}}
\newcommand{\VerbatimStringTok}[1]{\textcolor[rgb]{0.01,0.18,0.38}{#1}}
\newcommand{\WarningTok}[1]{\textcolor[rgb]{1.00,0.33,0.33}{#1}}
\providecommand{\tightlist}{%
\setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}\usepackage{longtable,booktabs,array}
\usepackage{calc} % for calculating minipage widths
% Correct order of tables after \paragraph or \subparagraph
\usepackage{etoolbox}
\makeatletter
\patchcmd\longtable{\par}{\if@noskipsec\mbox{}\fi\par}{}{}
\makeatother
% Allow footnotes in longtable head/foot
\IfFileExists{footnotehyper.sty}{\usepackage{footnotehyper}}{\usepackage{footnote}}
\makesavenoteenv{longtable}
\usepackage{graphicx}
\makeatletter
\def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth\else\Gin@nat@width\fi}
\def\maxheight{\ifdim\Gin@nat@height>\textheight\textheight\else\Gin@nat@height\fi}
\makeatother
% Scale images if necessary, so that they will not overflow the page
% margins by default, and it is still possible to overwrite the defaults
% using explicit options in \includegraphics[width, height, ...]{}
\setkeys{Gin}{width=\maxwidth,height=\maxheight,keepaspectratio}
% Set default figure placement to htbp
\makeatletter
\def\fps@figure{htbp}
\makeatother
% definitions for citeproc citations
\NewDocumentCommand\citeproctext{}{}
\NewDocumentCommand\citeproc{mm}{%
\begingroup\def\citeproctext{#2}\cite{#1}\endgroup}
\makeatletter
% allow citations to break across lines
\let\@cite@ofmt\@firstofone
% avoid brackets around text for \cite:
\def\@biblabel#1{}
\def\@cite#1#2{{#1\if@tempswa , #2\fi}}
\makeatother
\newlength{\cslhangindent}
\setlength{\cslhangindent}{1.5em}
\newlength{\csllabelwidth}
\setlength{\csllabelwidth}{3em}
\newenvironment{CSLReferences}[2] % #1 hanging-indent, #2 entry-spacing
{\begin{list}{}{%
\setlength{\itemindent}{0pt}
\setlength{\leftmargin}{0pt}
\setlength{\parsep}{0pt}
% turn on hanging indent if param 1 is 1
\ifodd #1
\setlength{\leftmargin}{\cslhangindent}
\setlength{\itemindent}{-1\cslhangindent}
\fi
% set entry spacing
\setlength{\itemsep}{#2\baselineskip}}}
{\end{list}}
\usepackage{calc}
\newcommand{\CSLBlock}[1]{\hfill\break\parbox[t]{\linewidth}{\strut\ignorespaces#1\strut}}
\newcommand{\CSLLeftMargin}[1]{\parbox[t]{\csllabelwidth}{\strut#1\strut}}
\newcommand{\CSLRightInline}[1]{\parbox[t]{\linewidth - \csllabelwidth}{\strut#1\strut}}
\newcommand{\CSLIndent}[1]{\hspace{\cslhangindent}#1}
\KOMAoption{captions}{tableheading}
\makeatletter
\@ifpackageloaded{bookmark}{}{\usepackage{bookmark}}
\makeatother
\makeatletter
\@ifpackageloaded{caption}{}{\usepackage{caption}}
\AtBeginDocument{%
\ifdefined\contentsname
\renewcommand*\contentsname{Table of contents}
\else
\newcommand\contentsname{Table of contents}
\fi
\ifdefined\listfigurename
\renewcommand*\listfigurename{List of Figures}
\else
\newcommand\listfigurename{List of Figures}
\fi
\ifdefined\listtablename
\renewcommand*\listtablename{List of Tables}
\else
\newcommand\listtablename{List of Tables}
\fi
\ifdefined\figurename
\renewcommand*\figurename{Figure}
\else
\newcommand\figurename{Figure}
\fi
\ifdefined\tablename
\renewcommand*\tablename{Table}
\else
\newcommand\tablename{Table}
\fi
}
\@ifpackageloaded{float}{}{\usepackage{float}}
\floatstyle{ruled}
\@ifundefined{c@chapter}{\newfloat{codelisting}{h}{lop}}{\newfloat{codelisting}{h}{lop}[chapter]}
\floatname{codelisting}{Listing}
\newcommand*\listoflistings{\listof{codelisting}{List of Listings}}
\makeatother
\makeatletter
\makeatother
\makeatletter
\@ifpackageloaded{caption}{}{\usepackage{caption}}
\@ifpackageloaded{subcaption}{}{\usepackage{subcaption}}
\makeatother
\ifLuaTeX
\usepackage{selnolig} % disable illegal ligatures
\fi
\usepackage{bookmark}
\IfFileExists{xurl.sty}{\usepackage{xurl}}{} % add URL line breaks if available
\urlstyle{same} % disable monospaced font for URLs
\hypersetup{
pdftitle={R for Novice Programmers (1e)},
pdfauthor={William Okech},
colorlinks=true,
linkcolor={blue},
filecolor={Maroon},
citecolor={Blue},
urlcolor={Blue},
pdfcreator={LaTeX via pandoc}}
\title{R for Novice Programmers (1e)}
\usepackage{etoolbox}
\makeatletter
\providecommand{\subtitle}[1]{% add subtitle to \maketitle
\apptocmd{\@title}{\par {\large #1 \par}}{}{}
}
\makeatother
\subtitle{First Steps with R and RStudio}
\author{William Okech}
\date{2024-01-01}
\begin{document}
\maketitle
\renewcommand*\contentsname{Table of contents}
{
\hypersetup{linkcolor=}
\setcounter{tocdepth}{2}
\tableofcontents
}
\listoffigures
\listoftables
\bookmarksetup{startatroot}
\chapter*{Welcome}\label{welcome}
\addcontentsline{toc}{chapter}{Welcome}
\markboth{Welcome}{Welcome}
This is the website for the book ``R for Novice Programmers'' written by
\href{https://www.williamokech.com}{William Okech}. The goal of this
book is to introduce non-programmers or those with very little
programming experience to the benefits of the R and RStudio software.
The main prerequisites for learners are basic knowledge of computer
applications and experience working with files and folders. This book
will primarily focus on the basic R concepts that are hardly emphasized,
but that may prove difficult for learners new to programming.
\href{https://wokech.github.io/r4novice/}{R for Novice Programmers:
First Steps with R and RStudio}© 2024 by
\href{https://www.williamokech.com/}{William Okech} is licensed under
\href{http://creativecommons.org/licenses/by-nc-nd/4.0/?ref=chooser-v1}{CC
BY-NC-ND 4.0}. The online version of this book is free to use.
Cover image was designed using \href{https://www.canva.com/}{Canva}.
This book was built with \href{https://quarto.org/}{Quarto}.
\bookmarksetup{startatroot}
\chapter*{Introduction}\label{introduction}
\addcontentsline{toc}{chapter}{Introduction}
\markboth{Introduction}{Introduction}
\section*{Why did I write this book?}\label{why-did-i-write-this-book}
\addcontentsline{toc}{section}{Why did I write this book?}
\markright{Why did I write this book?}
This book is primarily intended to cater to the needs of individuals who
have a desire to learn the basics of programming. I focus on R and
RStudio because their capabilities may be relevant to a wide variety of
individuals and organizations seeking to perform basic statistical
analysis and data visualization. Personally, my skills in R and RStudio
were gained via classroom instruction, online tutorials and videos, as
well as relevant blog posts. A significant disadvantage of some of these
resources is the assumption of prior programming knowledge. To address
this, I begin the book with instructions for downloading software,
navigating the R and RStudio interfaces, and an overview of the basics
of R to decrease the cognitive load on novices.
\section*{About the author}\label{about-the-author}
\addcontentsline{toc}{section}{About the author}
\markright{About the author}
The author of this book is a Certified Carpentries instructor and a
trainer with the Digital Research Academy. Additionally, the author
holds a PhD in Biomedical Engineering and has completed postdoctoral
fellowships in vascular biology and infectious diseases. Lastly, the
author is passionate about using R and RStudio to generate data-driven
visualizations to allow for a more in-depth understanding of public
policy issues.
\section*{Syllabus}\label{syllabus}
\addcontentsline{toc}{section}{Syllabus}
\markright{Syllabus}
At the end of the book, the student should be able to perform the tasks
listed in the syllabus below.
\begin{longtable}[]{@{}
>{\raggedright\arraybackslash}p{(\columnwidth - 4\tabcolsep) * \real{0.1125}}
>{\raggedright\arraybackslash}p{(\columnwidth - 4\tabcolsep) * \real{0.6875}}
>{\raggedright\arraybackslash}p{(\columnwidth - 4\tabcolsep) * \real{0.2000}}@{}}
\caption{Syllabus}\label{tbl-syllabus-.striped-.hover-tbl-colwidths5-75-20}\tabularnewline
\toprule\noalign{}
\begin{minipage}[b]{\linewidth}\raggedright
Chapter
\end{minipage} & \begin{minipage}[b]{\linewidth}\raggedright
Title
\end{minipage} & \begin{minipage}[b]{\linewidth}\raggedright
Date Completed
\end{minipage} \\
\midrule\noalign{}
\endfirsthead
\toprule\noalign{}
\begin{minipage}[b]{\linewidth}\raggedright
Chapter
\end{minipage} & \begin{minipage}[b]{\linewidth}\raggedright
Title
\end{minipage} & \begin{minipage}[b]{\linewidth}\raggedright
Date Completed
\end{minipage} \\
\midrule\noalign{}
\endhead
\bottomrule\noalign{}
\endlastfoot
& Introduction & \\
1 & Overview of R and RStudio & \\
2 & Download and Install R and RStudio & \\
3 & Navigating the R and RStudio interfaces & \\
4 & Managing your files and data & \\
5 & Importing data and saving analysis outputs & \\
6 & Basic arithmetic, arithmetic operators, and variables & \\
7 & The primary types of operators in R & \\
8 & Data Types & \\
9 & Vectors & \\
10 & Data Structures (Part I) & \\
11 & Data Structures (Part II) & \\
12 & Handling missing data & \\
& Conclusion & \\
& Appendix & \\
\end{longtable}
\section*{Sample chapter design}\label{sample-chapter-design}
\addcontentsline{toc}{section}{Sample chapter design}
\markright{Sample chapter design}
Each lesson will follow a pre-described format
\begin{enumerate}
\def\labelenumi{\roman{enumi}.}
\item
Questions to be addressed
\item
Learning objectives
\item
Lesson content
\item
Practice exercises
\item
Lesson summary
\end{enumerate}
The learners are encouraged to work through each chapter sequentially.
For each chapter, the learner should first review the questions to be
addressed and learning objectives. Next, the student should read through
the lesson content and ensure that the questions and learning objectives
sections have been addressed. Finally, the learners should do the
practice exercises to reinforce the newly learned concepts and review
the lesson summary.
\section*{Feedback}\label{feedback}
\addcontentsline{toc}{section}{Feedback}
\markright{Feedback}
Feedback can be provided using a GitHub pull request:
\href{https://github.com/wokech/r4novice}{Link}
\section*{Summary}\label{summary}
\addcontentsline{toc}{section}{Summary}
\markright{Summary}
Overall, I believe that this book will increase both the knowledge and
confidence levels of novice programmers and allow them to perform basic
statistical analysis and simplify everyday computational tasks at home
or in their workplaces. In the next chapter, I will provide a basic
overview of the R and RStudio ecosystem.
\bookmarksetup{startatroot}
\chapter{Overview of R and RStudio}\label{sec-overview}
\section{Questions}\label{questions}
\begin{itemize}
\item
What is R? How is it related to RStudio?
\item
Why is R considered a powerful language for statistical computing and
data analysis?
\item
What are some common uses of R in various fields?
\item
What advantages does R offer over other programming languages for data
science tasks?
\end{itemize}
\section{Learning Objectives}\label{learning-objectives}
\begin{itemize}
\item
Learn about the historical background of R and RStudio.
\item
Understand the uses and primary advantages of R and RStudio.
\item
Explore the various applications of R across different industries.
\end{itemize}
\section{Lesson Content}\label{lesson-content}
\subsection{Why learn R and RStudio?}\label{why-learn-r-and-rstudio}
Both R and Studio are free, open-source software tools that are widely
used for statistical analysis and data visualization. R is a programming
language that enables the use of code to analyze data. The primary
function of the R language is statistical analysis, and this can be
performed directly in the R console. To ease the analysis process and
enhance usability, an integrated development environment (IDE), such as
RStudio is recommended. The RStudio IDE is a user-friendly interface
that allows the learner to manage multiple script files, use the
command-line terminal, easily access file inputs and outputs, and review
file/analysis history.
The R programming language software was developed by Ross Ihaka and
Robert Gentleman in 1993 (published as open-source in 1995) when they
were based at the University of Auckland. \emph{Fun fact: R represents
the first letter of the first names of the creators}. The software is
utilized by individuals working for various organizations, ranging from
academic institutions and healthcare organizations to financial services
and information technology companies. In January 2024, the
\href{https://pypl.github.io/PYPL.html}{PopularitY of Programming
Language (PYPL) Index}, which is created by analyzing how often language
tutorials are searched on Google, demonstrated that R was the 6th most
popular programming language. However, in the same period, the
\href{https://www.tiobe.com/tiobe-index/}{TIOBE} index indicated that R
was the 23rd most popular language. This may result from different
methodologies for developing the rankings. RStudio is an integrated
development environment (IDE) for R that was developed by JJ Allaire.
This software contains tools that make programming in R easier.
RStudio extends R's capabilities by making it easier to import data,
write scripts, and generate visualizations and reports. The company
RStudio (now Posit since 2022) was founded in 2009 with the main goal of
``creating high quality open-source software for data scientists.''
\subsection{Uses of R and RStudio}\label{uses-of-r-and-rstudio}
\begin{enumerate}
\def\labelenumi{\roman{enumi}.}
\item
The R and RStudio console can be used as a complex scientific
calculator.
\item
The values of various data types can be assigned to variables using
the symbol \texttt{\textless{}-} or \texttt{=}.
\item
Built-in functions can be used to manipulate variables.
\item
Built-in datasets can be accessed internally for analysis.
\item
New datasets can be imported, and new functions can be created for
custom analysis.
\item
To aid in computational analysis, there exists a large package library
(\href{https://cran.r-project.org/}{CRAN}), as well as a lot of
software in development to aid in computational analysis.
\end{enumerate}
\subsection{Primary advantages of R and
RStudio}\label{primary-advantages-of-r-and-rstudio}
\begin{enumerate}
\def\labelenumi{\roman{enumi}.}
\item
R and RStudio are free and open-source software programs, which makes
them accessible to anyone with a computer and an internet connection.
This accessibility is key in enabling learners from all socioeconomic
levels and geographic regions to have a chance to work with
statistical software,
\item
Very many user communities exist for the R/RStudio software. These
communities (listed in the Appendix) provide learning support and
assist with technical challenges,
\item
Numerous freely available packages/extensions have been developed by
the R and RStudio user communities to facilitate all forms of
computational analysis, visualization, and publication. The
(\href{https://cran.r-project.org/}{CRAN}) has packages that contain
datasets as well as allow one to perform statistical analysis and data
visualization,
\item
R and RStudio allow for reproducible analysis where scripts and
workflows can be shared with fellow users, and,
\item
The R/RStudio software is cross-platform, which means that it can be
used on Linux, Windows, and Mac operating systems.
\end{enumerate}
\subsection{Applications of R in different
industries}\label{applications-of-r-in-different-industries}
\begin{enumerate}
\def\labelenumi{\roman{enumi}.}
\item
Bioinformatics and Healthcare: epidemiological studies, clinical trial
analysis, and genetic data analysis.
\item
Financial Modelling and Risk Analysis: risk management, algorithmic
trading, trading strategies and analysis, time series analysis, and
portfolio optimization.
\item
Retail and Marketing: customer analytics, sales forecasting, market
research, web analytics, and customer segmentation.
\item
Social Sciences and Humanities: text analysis, surveys and opinion
research, social trend analysis, and policy analysis.
\item
Statistics and Data Analysis: hypothesis testing, data visualization,
regression modelling, and statistical inference.
\item
Environmental Science and Climate Change: forecasting weather
patterns, modelling climate change, monitoring pollution levels, and
ecological modelling.
\end{enumerate}
\section{Exercises}\label{exercises}
As you embark on your R/RStudio learning journey, I have listed (below)
a few questions for you to think about before we get started with the
lessons.
\begin{enumerate}
\def\labelenumi{\roman{enumi}.}
\item
Why do you want to learn R and RStudio?
\item
Do you currently use any other software tools for data analysis and
visualization? What are the limitations of these tools?
\item
What are some key differences between R and other statistical
programming languages like SAS or SPSS?
\item
What tasks do you hope to accomplish after completing this training?
\item
Explore the various R/RStudio communities listed in the appendix and
consider joining any one of them. What is the role of the R community
in the development and support of R?
\item
Browse some popular R packages (on
\href{https://cran.r-project.org/}{CRAN} or
\href{https://r-universe.dev/search/}{R-Universe}) used for different
tasks like data visualization and statistical analysis. Pick one
package that interests you and read about its capabilities.
\end{enumerate}
\section{Conclusion}\label{conclusion}
I hope you enjoyed learning about the history of R and RStudio, and have
seen the advantages of using these tools for the diverse computational
tasks in your fields of practice. Additionally, we discussed the
numerous applications of R in various industries. In the next chapter,
we will look at how to download and install both R and RStudio on your
local computer.
\bookmarksetup{startatroot}
\chapter{Download and Install R and RStudio}\label{sec-download-install}
\section{Questions}\label{questions-1}
\begin{itemize}
\item
How does one install R and RStudio on their personal computer?
\item
Can RStudio be used online via a cloud-based service?
\item
Is it possible to work with alternative code editors when using R?
\item
What steps are involved in installing RStudio?
\end{itemize}
\section{Learning Objectives}\label{learning-objectives-1}
\begin{itemize}
\item
Install the R programming language on your local machine.
\item
Install RStudio as an integrated development environment (IDE) for R
on your local machine.
\item
Create an RStudio Cloud Account on the Posit Website.
\item
Learn how to use alternative code editors.
\end{itemize}
\section{Lesson Content}\label{lesson-content-1}
\subsection{Introduction}\label{introduction-1}
Both the R and RStudio software are required to make full use of the R
programming environment. R is the programming language, while RStudio is
the integrated development environment (IDE) that has an easy-to-use
interface. Here, we will focus on downloading R and RStudio for Windows
from the respective websites. The instructions for downloading these two
programs on Mac/Linux operating systems are available on the download
websites.
\subsection{Install R}\label{install-r}
To install R on your personal computer, visit the R Project for
Statistical Computing's Comprehensive R Archive Network
\href{https://cloud.r-project.org/}{CRAN}. Follow the illustrated steps
shown below:
\subsubsection{Step 1}\label{step-1}
On the CRAN homepage, select the appropriate version of R for your
operating system (Linux, macOS, or Windows; see
Figure~\ref{fig-cran-1}).
\begin{figure}
\centering{
\includegraphics{images/downloading/r_cran_1.png}
}
\caption{\label{fig-cran-1}The CRAN Homepage (Part 1)}
\end{figure}%
\subsubsection{Step 2}\label{step-2}
If installing R for the 1st time, click on ``base''
(Figure~\ref{fig-cran-2}).
\begin{figure}
\centering{
\includegraphics{images/downloading/r_cran_2.png}
}
\caption{\label{fig-cran-2}The CRAN Homepage (Part 2)}
\end{figure}%
\subsubsection{Step 3}\label{step-3}
Click on the ``Download'' link for the latest version of R that is
currently available (at the time of this writing, it was R-4.3.2). Once
downloaded, run the executable file and wait for the software to be
installed (Figure~\ref{fig-cran-3}).
\begin{figure}
\centering{
\includegraphics{images/downloading/r_cran_3.png}
}
\caption{\label{fig-cran-3}The CRAN Homepage (Part 3)}
\end{figure}%
\subsubsection{Step 4}\label{step-4}
Once R is installed, open up the R software. The R graphical user
interface should be similar to what is depicted below
(Figure~\ref{fig-r-console-1}).
\begin{figure}
\centering{
\includegraphics{images/downloading/r_console_1.png}
}
\caption{\label{fig-r-console-1}The R Console}
\end{figure}%
\subsection{Install RStudio}\label{install-rstudio}
The RStudio IDE can be obtained from the ``Download'' section of the
Posit \href{https://posit.co/download/rstudio-desktop/}{website}.
Install the software by clicking on the ``Download RStudio Desktop for
Windows'' button and running the downloaded program
(Figure~\ref{fig-rstudio-1}).
\begin{figure}
\centering{
\includegraphics{images/downloading/rstudio_1.png}
}
\caption{\label{fig-rstudio-1}The Posit/RStudio Download Page}
\end{figure}%
Once installed, verify that the RStudio software has a similar graphical
user interface to the one depicted in the image below
(Figure~\ref{fig-rstudio-console-1}).
\begin{figure}
\centering{
\includegraphics{images/downloading/rstudio_console_1.png}
}
\caption{\label{fig-rstudio-console-1}The RStudio Console}
\end{figure}%
\subsection{Create an RStudio Cloud Account on the Posit
website}\label{create-an-rstudio-cloud-account-on-the-posit-website}
Posit (formerly RStudio) Cloud lets the user access the RStudio
interface from their internet browsers (Figure~\ref{fig-r-cloud-1}).
Using this option does not require any installation or specific software
configuration to be implemented. Posit Cloud offers a
\href{https://posit.cloud/plans/free}{free plan} for casual users
(without the need for a paid plan) and there is no need for dedicated
hardware. Additionally, Posit provides a comprehensive
\href{https://posit.cloud/learn/guide}{guide} for first-time users.
\subsubsection{Step 1}\label{step-1-1}
Access the Posit Cloud Website (Figure~\ref{fig-r-cloud-1}).
\begin{figure}
\centering{
\includegraphics{images/downloading/r_cloud_1.png}
}
\caption{\label{fig-r-cloud-1}The Posit/RStudio Cloud Homepage}
\end{figure}%
\subsubsection{Step 2}\label{step-2-1}
Sign up for a new user account (Figure~\ref{fig-r-cloud-2}).
\begin{figure}
\centering{
\includegraphics{images/downloading/r_cloud_2.png}
}
\caption{\label{fig-r-cloud-2}The Posit/RStudio Cloud Login Page}
\end{figure}%
\subsubsection{Step 3}\label{step-3-1}
Log in to the new account, and you should see the page shown below
(Figure~\ref{fig-r-cloud-3}). It includes the workspace where all
projects will be hosted. On the top right-hand side of the website is a
button that allows one to create a ``New Project.'' Additionally, the
``Learn'' and ``Help'' sections on the left panel can assist with
troubleshooting.
\begin{figure}
\centering{
\includegraphics{images/downloading/r_cloud_3.png}
}
\caption{\label{fig-r-cloud-3}The Posit/RStudio Cloud Workspace}
\end{figure}%
\subsubsection{Step 4}\label{step-4-1}
Create an R script to allow for code editing
(Figure~\ref{fig-r-cloud-console-1}).
\begin{figure}
\centering{
\includegraphics{images/downloading/r_cloud_console_1.png}
}
\caption{\label{fig-r-cloud-console-1}The Posit/RStudio Cloud Console}
\end{figure}%
\subsection{Using alternative code editors to work with R (Advanced
Users)}\label{using-alternative-code-editors-to-work-with-r-advanced-users}
Visual Studio (VS) Code is a code editor that can be used with various
programming languages. For users that have previous experience with this
code editor and would like to use it when reading this book, it is
possible to use VS Code as an alternative to RStudio. After installing
R, the ``R Extension for Visual Studio Code'' can be installed in the
``Extensions'' menu (Figure~\ref{fig-r-vscode}).
\begin{figure}
\centering{
\includegraphics{images/downloading/r_vscode.png}
}
\caption{\label{fig-r-vscode}The R interface on Visual Studio Code}
\end{figure}%
\section{Exercises}\label{exercises-1}
\begin{enumerate}
\def\labelenumi{\roman{enumi}.}
\tightlist
\item
Download and install R and RStudio (\emph{If you have not already done
so}).
\item
Describe the steps involved in installing R on a Windows operating
system.
\item
Are there any specific considerations when installing R on a macOS or
Linux system?
\item
Set up a free RStudio Cloud Account on the
\href{https://posit.cloud/}{Posit Website}.
\item
Compare the local RStudio with the cloud-based RStudio and list the
potential benefits/disadvantages of both.
\item
Verify your R installation by running a simple R script that prints
``Hello, R! My name is (fill in the blank)'' to the console.
\item
Can you customize the appearance or behavior of RStudio according to
your preferences?
\end{enumerate}
\section{Summary}\label{summary-1}
In this chapter, we have provided a step-by-step guide for downloading R
and RStudio on the learner's personal computer. Additionally, the
learner has been shown how to set up an RStudio Cloud account on the
Posit website, which allows for the use of R/RStudio using a web-based
browser. Lastly, the learner has been shown how to access R/RStudio
using alternative code editors such as Visual Studio Code. Overall,
having a functional R and RStudio environment is key to gaining the most
out of your learning journey. In the next chapter, we will navigate the
R/RStudio interfaces and explain the various panes and menu options.
\bookmarksetup{startatroot}
\chapter{Navigating the R and RStudio interfaces}\label{sec-navigating}
\section{Questions}\label{questions-2}
\begin{itemize}
\item
What are the main components of the R interface?
\item
How is the RStudio Integrated Development Environment (IDE) organized,
and what are its key features?
\item
How does one navigate the R and RStudio interfaces?
\item
What are the functions of the various RStudio panes?
\end{itemize}
\section{Learning Objectives}\label{learning-objectives-2}
\begin{itemize}
\item
Identify and understand the main components of the R interface.
\item
Navigate the RStudio IDE and comprehend its organizational structure.
\item
Customize your RStudio environment to suit your preferences.
\item
Understand the roles of the console and menu options in the R
software.
\item
Review the various panes and menu options in the RStudio software.
\item
Learn the various keyboard shortcuts that can improve speed and
efficiency.
\end{itemize}
\section{Lesson Content}\label{lesson-content-2}
\subsection{The R interface}\label{the-r-interface}
\subsubsection{Menu options}\label{menu-options}
The R graphical user interface opens up with a console where you can
start writing and executing code (Figure~\ref{fig-r-console-1}).
Additionally, there exists a toolbar that contains shortcuts to commonly
used functions. The menu bar allows one to perform various operations
within the R software. The various menu bar options and a brief summary
of their main uses are listed below:
\begin{itemize}
\tightlist
\item
File: Create new scripts and workspaces, as well as review the session
history.
\item
Edit: Copy, paste, and edit, as well as set up the graphical user
interface (GUI) preferences.
\item
View: Include the toolbar and status bar within the GUI.
\item
Misc: Control computations and review objects.
\item
Packages: Install, load, and update packages.
\item
Windows: Arrange multiple windows in the learner's preferred
orientation.
\item
Help: Find links to FAQs, manuals, and help functions.
\end{itemize}
\begin{figure}
\centering{
\includegraphics{images/navigating/r_console_1.png}
}
\caption{\label{fig-r-console-1}The R Console}
\end{figure}%
\subsection{RStudio interface (Panes)}\label{rstudio-interface-panes}
When opened for the 1st time, the RStudio interface will have 3 panes:
Console, Environment, and Navigation. To include the 4th required panel,
click on ``File'' --\textgreater{} ``New File'' --\textgreater{} ``R
Script''. Now that the 4 panes are open, let us review the functions of
each panel shown below.
\begin{figure}
\centering{
\includegraphics{images/navigating/rstudio_console_1.png}
}
\caption{\label{fig-rstudio-console-1}The RStudio Console}
\end{figure}%
\subsubsection{Script Pane (Text Editor)}\label{script-pane-text-editor}
The script pane allows the user to write, edit, and save code. This code
can then be run, and the output will be displayed in the console pane.
\subsubsection{Console Pane}\label{console-pane}
In the console pane, one can write and edit code, but not save. Within
the console, one can run one line of code at a time. Additionally, one
can access the terminal tab and run code via the command line. Lastly,
we can access the ``Background Jobs'' tab to monitor the progress of R