Data Days

What is R?

An OPEN-SOURCE programming LANGUAGE and free software ENVIRONMENT for STATISTICAL COMPUTING and GRAPHICS

Learn more at https://www.r-project.org/

Download R at https://cran.r-project.org/

The R Interface

> R uses a ...

> command line interface |

How does R work?

Basic Usage

"R doesn’t protect you from yourself: you can easily shoot yourself in the foot. As long as you don’t aim the gun at your foot and pull the trigger, you won’t have a problem."

- Hadley Wickham (Advanced R; 2014)

Hadley Wickham https://github.com/hadley

RStudio https://www.rstudio.com/

The RStudio IDE

Functional Approach

R is a functional programming language. Every operation is a function call.

1 + 2
`+`(1, 2)
[1] 3
[1] 3

"To understand computations in R, two slogans are helpful:

  • Everything that exists is an object
  • Everything that happens is a function call"

- John Chambers

Package Functions

Don't reinvent the wheel!

R is highly extensible through packages

Many amazing packages come installed with R. See the Packages pane in RStudio or run the following command in the R console: installed.packages()

To access the functions (and other objects) from a package, first load the package using the library() function.

qplot(x = Petal.Width, y = Petal.Length, data = iris)
Error: could not find function "qplot"
library(ggplot2)
qplot(x = Petal.Width, y = Petal.Length, data = iris)

* Can also use the double-colon operator, for example: ggplot2::qplot()

Help!

Most R functions come packaged with robust documentation, which you can access by using the help() function:

# pull up help page for the mean function
help(mean)

Also find terrific community help online:

Google

GitHub

StackOverflow

Package Overview

Fundamental unit of reproducible R code

Includes:

  • R functions
  • Documentation
  • Sample data

Standards for creating

May depend on other packages

Typically domain specific

CRAN

The Comprehensive R Archive Network

A collection of sites ("mirrors") that carry identical material, consisting of the R distribution(s), the contributed extensions, documentation for R and binaries.

(i.e. main repository for R and packages)

Master site: https://CRAN.R-project.org/

Download the latest version of R

Over 7,800 packages available

Install packages from CRAN:

install.packages("dplyr")

Essential Packages: dplyr

Grammar for Data Manipulation