Introduction to R

Biochemistry laboratories - 201

Jean-Yves Sgro [email protected]

Find this document here (short URL) today: http://bit.ly/2q1v9pd

Set-up

  • check your name on the attendees list
  • choose an iMac
  • login with your UW NetID with @wisc.edu
  • Since this is the first time this Mac "sees" you it will go through a quick set-up: simply skip using "Apple ID"

Finding R on the iMac

  • Click on the "Finder" at the bottom right of the "Dock" on the bottom of the screen.
  • This will open a new window.
  • On the left click on "Applications"
  • In the alphabetical list choose "R" or "R.app" with a icon that looks like: R icon
  • double click toopen the R program

R exercises

Hand-outs on the Biochemistry web site. Sh

Class evaluation

After class:

  • fill-in the one page "evaluation" form for this class

The evaluation is anonymous. Evaluation link on Qualtrics or type: the short URL: http://bit.ly/1LczY1L

bit.ly/1LczY1L

(beginning and end of short URL: number ONE and letter L in 1L )

Try R:

Then type R to start the program.

Install R:

R discussion/study groups in Madison

We generally meet every other week (opposite weeks as python). Tuesday at 2pm in MSB 6503. All experience levels are welcome to join us!

How R Works

  • variables, data, functions, results, etc., are stored in the active memory (RAM)

How R Works

  • All the actions of R are done on objects stored in the active memory of the computer (RAM:) no temporary files are used

R Objects

Warning **The name of an object must start with a letter(`A–Z` and `a–z`)**

but can include letters, digits (0–9), dots (.), and underscores (_).

R discriminates between UPPERcase and lowercase letters in the names of the objects, so that x and X can name two distinct objects (even under Windows).

Assign operator: <- and =

Assign values, list, etc. to an R object

Example: place value 15 inside object n

In [12]:
n <- 15

Now n contains value 15:

In [13]:
n
Out[13]:
15

which is equivallent to:

In [11]:
print(n)
[1] 15

Where is R Stored?

It depends on your operating system.

  • On Windwows: C:\\Program Files\\R\\R-3.3.3
  • On Mac: /Library/Frameworks/R.framework/Versions/3.3/Resources/library/
In [6]:
# .Library is a character string giving the location of the default library
.Library
Out[6]:
'/Library/Frameworks/R.framework/Resources/library'
In [7]:
# On this Mac: .libPaths is used for getting or setting the library trees 
# that R knows about (and hence uses when looking for packages)
.libPaths()
Out[7]:
'/Library/Frameworks/R.framework/Versions/3.2/Resources/library'

Today

Run R from R.app

  • Review R operators
  • Generate data
  • Manipulate R objects
  • Create graphics and plots

Other tutorials

Search engines will list a lot of R tutorials, here is just one:

Video tutorials also exist on YouTube, but at UW we also have access to Lynda.com video courses.

You may need to login with your NetID to see/access these.