R
and RStudio
R
Install the latest version of R
(4.3.1 as of September 5, 2023). R
itself is similar to an engine and chassis of a car, that is a bare minimum so that you can start driving. You need to follow steps below:
R
;R
.Note: If you are a Mac user and you see similar to the following warning messages during the startup
During startup - Warning messages:
1: Setting LC_CTYPE failed, using "C"
2: Setting LC_COLLATE failed, using "C"
3: Setting LC_TIME failed, using "C"
4: Setting LC_MESSAGES failed, using "C"
5: Setting LC_PAPER failed, using "C"
[R.app GUI 1.50 (6126) x86_64-apple-darwin9.8.0]
WARNING: You're using a non-UTF8 locale, therefore only ASCII characters will work. Please read R for Mac OS X FAQ (see Help) section 9 and adjust your system preferences accordingly. [History restored from /Users/nemo/.Rapp.history]
you need to follow steps below:
defaults write org.R-project.R force.LANG en_US.UTF-8
Caution: Install RStudio
only once R
has been installed and only in this order.
RStudio
is an integrated development environment for R
. Following up our example of the car, RStudio
is similar to additional parts, such as exterior, interior, air conditioner, etc. You can drive the vehicle without them, but life is much simpler and pleasant if they are present.
We will install the free version:
Note: To improve the quality of the code, we will limit the length of lines to 80 symbols. To display the margin in RStudio sourse editor:
Check yourself: Open RStudio
application. In the console you will see something as follows:
R version 4.3.1 (2023-06-16 ucrt) -- "Beagle Scouts"
Copyright (C) 2023 The R Foundation for Statistical Computing
Platform: x86_64-w64-mingw32/x64 (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
Note: Packages can be installed from both R
and RStudio
. The installed RStudio
is not required.
In this course we will utilize a number of packages. If a package is published on CRAN, then the procedure of installing the package is straightforward:
install.packages("package_name")
, where package_name
is the name of the desired package (e.g., “ggplot2”).Several packages, however, would have only development version (or simply be not published on CRAN). Then, knowing the GitHub link to the repo, one could follow the steps below:
devtools
package (if it has not yet been installed) as usual (as shown above).devtools::install_github("username/repo")
and hit the Enter/return key to execute the command in the console, where username
is the username of the owner of the repo, and repo
is the name of the repo.For homeworks you will use the following packages from CRAN: "tidyverse"
, "devtools"
, "rmarkdown"
, "knitr"
, "shiny"
, "roxygen2"
.
Note: Before installing the "devtools"
package, you will most certainly need to install building tools.
For Windows, you need to install RTools.
For Mac, you need to install XCode.
Check this link for more details.
Note: Packages should be installed only once. No needs to install them every time when you want to use them (it is the same as installing Skype every time you want to call your parents). That is why it is better to do it in console, not in source editor.
Check yourself: To check if a package was installed successfully, use "name_of_package" %in% rownames(installed.packages())
.