Getting Started in R: Installation
To use R code, you need to install the following:
- Base R Program from here: https://cran.r-project.org/ (It's Free!)
- Makes R more user friendly to run: https://rstudio.com/products/rstudio/download/ (Also Free!)
Getting Started in R: Installing Packages
Key Points
- R was developed by statisticians and data analysts as an interactive environment for data analysis.
- Some of the advantages of R are that (1) it is free and open source, (2) it has the capability to save scripts, (3) there are numerous resources for learning, and (4) it is easy for developers to share software implementation.
- Expressions are evaluated in the R console when you type the expression into the console and hit Return.
- A great advantage of R over point and click analysis software is that you can save your work as scripts. “Base R” is what you get after you first install R. Additional components are available via packages.
Code: Install Packages Example
#installing the dslabs package
install.packages("dslabs")
#loading the dslabs package into the R session
library(dslabs)
Advanced
- The base version of R is quite minimal, but you can supplement its functions by installing additional packages.
- We will be using tidyverse and dslabs packages for this course.
- Install packages from R console: install.packages("pkg_name")
- Install packages from RStudio interface: Tools > Install Packages (allows autocomplete)
- Once installed, we can use library(pkg_name) to load a package each time we want to use it
- If you try to load a package with library(blahblah) and get a message like Error in library(blahblah) : there is no package called 'blahblah', it means you need to install that package first with install.packages().
- You can add the option dependencies = TRUE, which tells R to install the other things that are necessary for the package or packages to run smoothly. Otherwise, you may need to install additional packages to unlock the full functionality of a package.
Code: More Installing Packages & Looking at Installed Packages
install.packages("dslabs") # to install a single package
install.packages(c("tidyverse", "dslabs")) # to install two packages at the same time
installed.packages() # to see the list of all installed packages
RStudio: How to Use
https://education.rstudio.com/learn/beginner/
https://rstudio.com/resources/cheatsheets/
In general Rstudio helps you out within its GUI by using ?#anything.