Welcome!

All course materials at tinyurl.com/introRDatasite

Welcome! Who are you?

  • What part of your education are you in? (Bachelor, PhD, prof…)

  • What is your faculty/background? (Economics, Medicine, Biology…)

  • What is your motivation for learning R?

  • What is your experience with R?

This morning’s schedule

  •   9:30   Introductions

  • 10:00   Base R + Exercises 1- 6

  • 11:25   Recap & questions

  • 11:30   Coffee break

  • 11:45   Programming + Exercises 7-9

  • 12:45   Lunch break

  • 13:30   Reconvene for afternoon program

Introduction to R & Data

Part 1: Basics of R

What is R

  • A widely used programming language for data analysis
  • Based on statistical programming language S (1976)
  • Developed by Ross Ihaka & Robert Gentleman (1995)
  • Very active community, with many (often subject-specific) packages
  • Open source, and interoperable!

We will work in Rstudio

  • Integrated Development Environment (IDE) for R
  • Founded by J.J. Allaire, available since 2010
  • Bloody useful! Let’s take a look: please open RStudio!

The Rstudio interface

Course materials

All course materials, videos, information & resources are at tinyurl.com/introRDatasite.

  1. Download the course materials.

  2. Store them in a local (i.e. not on a mounted drive), accessible location.

  3. Unzip the download to create a single folder. What animal is displayed on animal.png?

  4. Double-click the course-materials.Rproj file. Or: Go to File > Open Project > select course-materials.Rproj > Open

  5. From the ‘Files’ menu (bottom right), click baseR_exercises.Rmd.

R project files

When you start programming for yourself:

  • Create a folder dedicated to your project
  • Start a new R project: File > New Project > Existing Directory
  • An .RProj file will be created

Advantages:

  • Automatically set your working directory to that folder
  • Automatically retrieve only the history and objects from that R project
  • More reproducible (relative vs. absolute paths)
getwd()

Running R code

In the baseR_exercises.Rmd:

You can execute Exercise 0 chunk as a whole with the green triangle:

In a script/Rmarkdown document

  • Place your cursor in the line of code you want to execute
  • Press or ctrl + enter
  • When running multiple lines: select all lines, then press ‘Run’ or ctrl + enter

R syntax & data types

Variable assignment

You can assign both numbers and text to a variable:

x <- 6
x <- 'apple'
x <- "hello world"

You will see your variable (R object) appear in your Environment (top right panel).