2016-06-21

What is R? … and what does it do?

R is …

a language and environment for statistical computing and graphics
  • Free to use
  • Extensible
    • Over 7300 user contributed add-on packages currently on CRAN (The Comprehensive R Archive Network)
    • at least as many packages on github repositories
  • Powerful
    • With the right tools, get more work done, faster.
  • Flexible
    • Not a question of can, but how.
  • Frustrating
    • Flexibility comes at a cost (easy to shoot yourself in the foot!).

R does …

  • Graphics, statistics, machine learning, etc.
  • Data acquisition, munging, management
  • Literate programming (dynamic reports)
  • Web applications

We will touch on all of these aspects. Slides and material are available at http://heike.github.io/rwrks/summerschool.

Installing R

  • Go to http://www.r-project.org/
  • Click the CRAN link on the left, and pick a download site (0-Cloud is a good choice)
  • Choose link based on your OS
  • On Windows, choose the "base" subdirectory to install R.
  • On OS X, choose the .pkg file to install R.

Installing RStudio

  • Browse to https://www.rstudio.com/
  • Mouse over Products and click RStudio
  • Choose RStudio Desktop
  • Click Download RStudio Desktop
  • Choose the installer appropriate for your platform

RStudio is …

From Julie Lowndes:

If R were an airplane, RStudio would be the airport, providing many, many supporting services that make it easier for you, the pilot, to take off and go to awesome places. Sure, you can fly an airplane without an airport, but having those runways and supporting infrastructure is a game-changer.

The RStudio IDE

  1. Source editor
    • Docking station for multiple files
    • Useful shortcuts ("Knit")
    • Highlighting/Tab-completion
    • Code-checking (R, HTML, JS)
    • Debugging features
  2. Console window
    • Highlighting/Tab-completion
    • Search recent commands
  3. Other tabs/panes
    • Graphics
    • R documentation
    • Environment pane
    • File system navigation/access
    • Tools for package development, git, etc

Create a project

Create a project to contain all of the material covered in this set of tutorials:

  • File -> New Project -> New Directory -> Empty Project

Hello R Markdown!

  • File -> New File -> R Markdown -> OK -> Knit HTML

What is R Markdown?

R Markdown is an authoring format that enables easy creation of dynamic documents, presentations, and reports from R. It combines the core syntax of markdown (an easy-to-write plain text format) with embedded R code chunks that are run so their output can be included in the final document. R Markdown documents are fully reproducible (they can be automatically regenerated whenever underlying R code or data changes).

For your reference

  • Download, save, and open the document which generates these slides in RStudio (you can do that with this R code):
curl::curl_download(
  "https://raw.githubusercontent.com/heike/rwrks/gh-pages/summerschool/01-Introduction-to-R/knitr/0-getting-started.Rmd",
  "0-getting-started.Rmd"
)
file.edit("0-getting-started.Rmd")
  • Download, save, and open the corresponding R script.
curl::curl_download(
  "https://raw.githubusercontent.com/heike/rwrks/gh-pages/summerschool/01-Introduction-to-R/code/0-getting-started.R",
  "0-getting-started.R"
)
file.edit("0-getting-started.R")

Error message?

If R is complaining about not having the package curl, run

install.packages("curl")

and try again