MTH 209 Data Manipulation and Management

Lesson 1: An Overview of R, RStudio, and R Markdown

Ying-Ju Tessa Chen
ychen4@udayton.edu
University of Dayton

What is R?

R is a statistical programming language. Developed by statisticians Ross Ihaka and Robert Gentleman, R is one of the most popular programming languages in the industry. It is used in almost everywhere, ranging from finance and banking to medicine and manufacturing. It can be used in disciplines like statistics, computer science, economics and economic modelling, cyber security, information systems, health care, engineering and so on.

To update R, run the following code.

# Install installr (if not already installed)
if(require(installr)==FALSE) install.packages("installr") 

# using the package
require(installr)

# update R to the latest version
updateR()

RStudio

RStudio is an integrated development environment (IDE) for R.

 

 

What is R markdown?

R Markdown is a file format for creating dynamic documents with R and RStudio. RMarkdown documents are written in Markdown which has easy-to-write plain text format with embedded R code.

In order to create a Rmarkdown document, we click File and then find New File, R markdown …, and Document. There are three options:

  • HTML
  • PDF (Its output requires TeX.)
  • Word (It requires an installation of MS Word.)

 

An Overview of R Markdown Documents

In the following, we show an example of the header of a R markdown file.

We can use the output option to manipulate which document we would like to have.

To render a R Markdown document into its final output format, we can click the Knit button to render the document in RStudio and RStudio will show a preview of it. The corresponding output file is saved in the folder where the markdown file is.

The further settings for presentations could be found at R Markdown Cookbook and R Markdown: The Definitive Guide.

Some Useful Keyboard Shortcuts

  • Ctrl-A to select all items
  • Ctrl-C to copy
  • Ctrl-F to find text in a page
  • Ctrl-N to start a new file in an editor
  • Ctrl-O to open a file from the disk
  • Ctrl-S to save
  • Ctrl-T to open a new tab in a browser
  • Ctrl-V to paste
  • Ctrl-X to cut
  • Ctrl-Z to undo
  • Alt-Tab changes from window to window.
  • Alt-= to insert a new equation in MS Word
  • Command-C to copy
  • Command-F to find text in a page
  • Command-N to open a new Finder window
  • Command-O to open a file from the disk
  • Command-S to save
  • Command-V to paste
  • Command-X to cut
  • Command-Z to undo
  • Command-Tab changes from window to window.
  • Ctrl-= to insert a new equation in MS Word

See Mac keyboard shortcuts for more detail.

Where to get help

  1. To see documentation on any function in R, execute ?data.frame etc.
  2. Google it! (Better way to learn coding!)
  3. Ask questions online, for example: stackoverflow.com.

README

You can utilize the following single character keyboard shortcuts to enable alternate display modes (Xie, Allaire, and Grolemund (2018)):

Xie, Yihui, Joseph J Allaire, and Garrett Grolemund. 2018. R Markdown: The Definitive Guide. CRC Press.