Install R
and RStudio
The R language and its tools are built by people from around the world. They help you perform data analysis in an easy to follow step-by-step fashion, much like a recipe for cookies. And once you find your favorite recipe, you can use it over again on new data or share it with your collaborators.
RStudio is the handy user interface we use to write R scripts and keep our projects organized. It isn’t required to use R, but it makes things a whole lot easier.
1. For state employees
State employees at MDH and other agencies may follow the steps below to install both R and RStudio all in one go:
- Open the Software Center
- Search for RStudio
- Choose the option with the blue R bubble shown below.
- If it doesn’t appear for you submit a service ticket to your local MNIT friends.
- Click
[ Install ]
- Heads up, you may need to click [ Install ] a second time for it to fully get the message
- Once it completes, you can search for RStudio in your Windows search bar and click the RStudio App to open.
RStudio
2. For outside folks and friends
If you have the permissions to install software on your work computer, or you would just like to use R on your personal computer, you may download R and RStudio for free from the following trustworthy sources:
Installing R
- Go to https://cloud.r-project.org/
- Click on the download link for your operating system, then click on base.
- Click on the download link at the top of the page to download R.
- Click on the downloaded file to install R.
Installing RStudio
After you have installed R, you can install RStudio.
- Go to https://rstudio.com/products/rstudio/download/
- Scroll down to the table, locate your operating system, and click the download link.
- Click on the downloaded file to install RStudio.
3. In the cloud
As a stop gap until you are able to install R locally, you can create an account at the link below and then you can use R right in your browser for the training.
The sections below are for reference and do not need to be completed before R camp begins.
Install R packages
R comes installed with many built-in functions and tools to help do your work. On top of this foundation, what is often referred to as base R, contributors from around the world have created tools that make R easier and accomplish more with your data. These add-ons are called packages
, and are made available to everyone to download for free. Below are a few examples, grouped into general categories.
Packages used in this training
Load data
readr
Load data from text files: tab, comma, and other delimited files
readxl
Load data from Excel
janitor
Clean and simplify column names
DBI
Load data from databases
haven
Load SAS, SPSS, and Stata files
sf
Load data from GIS shapefiles
Manipulate data
dplyr
Essential shortcuts to subset, summarize, rearrange, and join data sets.
tidyr
Reshape tables and unpack multiple inputs stored in single cell.
stringr
Tools to edit and clean text and character strings.
lubridate
Tools to format dates and perform calculations based on time.
Charts and visuals
ggplot2
Essential package for plots and charts.
Maps
leaflet
Display spatial data and make interactive maps.
sf
Simple features for GIS and maps, a spatial format using data frames to perform spatial analysis.
General
remotes
Install packages directly from online sources like GitHub and Gitlab.
Add R packages
To use a package you first need to install it – much like a free App for your phone. To get a jump start on the workshop, you can copy the text below and paste it into the RStudio console. The console is found on the left-side of the screen when you open RStudio.
new_packages <- c("readr", "readxl", "dplyr", "stringr", "tidyr",
"ggplot2", "lubridate", "janitor", "curl")
install.packages(new_packages)
Then press ENTER
to begin the installation. If all goes well, you should start to see some messages appear similar to this, which provide information on the installation progress.
Did it work? Try running the code below to load the readr
package from your library and see if it is installed.
Additional recommended packages
Charts and visuals
ggsave
Export charts in various formats and sizes.
hrbrthemes
, ggpomological
, ggthemes
Chart themes for ggplot.
viridis
, wesanderson
, ghibli
Color palettes.
rmarkdown
Write summary reports and save as PDF, Word document, presentation, or website.
Load data
RODBC
Load data from Access and Oracle databases.
RMySQL
, RPostgresSQL
, and RSQLite
for connecting to SQL databases.
pdftools
Read PDF documents.
googledrive
Read and write files to your Google Drive.
foreign
Load data from Minitab and Systat.
R.matlab
Load data from Matlab.
Manipulate data
stringr
Tools to edit and clean text and character strings.
Maps
tidycensus
Download Census and American Community Survey data.
Update R packages
There are two places to update R packages in RStudio.
1. In the Files and Plots
area in the bottom right, under the Packages
tab:
Click the green Update button next to Install.
2. In the Tools
tab above at the top above the Code Editor:
Choose the 2nd option -> “Check for Package Updates…”