{ "cells": [ { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "# Introduction to R\n", ">Biochemistry laboratories - 201\n", ">\n", ">Jean-Yves Sgro -jsgro@wisc.edu\n", "\n", "Find this document here (short URL) today: [**`http://bit.ly/2q1v9pd`**](http://bit.ly/2q1v9pd)\n", "\n" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "# Set-up\n", "\n", "- check your name on the attendees list\n", "- choose an iMac\n", "- login with your UW NetID _with_ `@wisc.edu`\n", "- Since this is the first time this Mac \"sees\" you it will go through a quick set-up: simply **skip** using \"Apple ID\"" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "# Finding R on the iMac\n", "\n", "- Click on the \"Finder\" at the bottom right of the **\"Dock\"** on the bottom of the screen.\n", "- This will open a new window.\n", "- On the left click on **\"Applications\"**\n", "- In the alphabetical list choose **\"R\"** or **\"R.app\"** with a icon that looks like: ![R icon](https://developer.r-project.org/Logo/Rlogo-5.jpg)\n", "- double click toopen the **R** program\n" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "# R exercises\n", "\n", "Hand-outs on the Biochemistry web site.\n", "Sh\n", "- (SHort URL) http://go.wisc.edu/257ida " ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "# Class evaluation\n", "After class:\n", "- fill-in the one page \"evaluation\" form for this class \n", "\n", "\n", "The evaluation is anonymous. [Evaluation link on Qualtrics](https://uwmadison.co1.qualtrics.com/SE/?SID=SV_dhD0qVPd85NsNmZ) or type:\n", "the short URL: [**`http://bit.ly/1LczY1L`**](http://bit.ly/1LczY1L) \n", "\n", "# bit.ly/1LczY1L\n", "\n", "(beginning and end of short URL: number ONE and letter L in `1L` )\n" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "# Try R:\n", "\n", "- **Try R** without installing anything: the embedded R within a browser: http://www.tutorialspoint.com/r_terminal_online.php\n", "\n", "Then type `R` to start the program.\n", "\n", "\n", "# Install R:\n", "\n", "- Download `R` for your computer and specific OS: https://cran.r-project.org/\n" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "# R discussion/study groups in Madison\n", "\n", "- R Study Group from ComBEE (\n", "Computational Biology, Ecology, & Evolution @ UW-MadisonComputational Biology, Ecology, & Evolution @ UW-Madison)\n", "https://sites.google.com/a/wisc.edu/combee/r-study-group\n", "\n", "We generally meet every other week (opposite weeks as python).\n", "*Tuesday at 2pm in MSB 6503.*\n", "All experience levels are welcome to join us!\n", "\n", "- Mad R: MadR - Madison R Programming UseRs Group http://www.meetup.com/MadR-Madison-R-Programming-UseRs-Group/\n", " - Meet once a month, Madison Public library\n" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "# How R Works\n", "\n", "- variables, data, functions, results, etc., are stored in the active memory (RAM)\n", "\n", "![](https://biochem.wisc.edu/sites/default/files/facilities/bcrf/tutorials/R/R_intro/media/image4.png)" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "# How R Works\n", "\n", "- All the actions of R are done on objects stored in the active memory of the computer (RAM:) no temporary files are used \n", "\n", "![](https://biochem.wisc.edu/sites/default/files/facilities/bcrf/tutorials/R/R_intro/media/image5.png)" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "# R Objects\n", "\n", "| |\n", "|--------| ---------------------------------------------- |\n", "|![Warning](https://biochem.wisc.edu/sites/default/files/facilities/bcrf/tutorials/R/R_intro/media/image8.jpeg \"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).|\n", "| | |\n" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "# Assign operator: `<-` and `=` \n", "Assign values, list, etc. to an R object\n", "\n", "## Example: place value 15 inside object `n`" ] }, { "cell_type": "code", "execution_count": 12, "metadata": { "collapsed": true, "slideshow": { "slide_type": "fragment" } }, "outputs": [], "source": [ "n <- 15" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "fragment" } }, "source": [ "## Now `n` contains value 15:" ] }, { "cell_type": "code", "execution_count": 13, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "15" ], "text/latex": [ "15" ], "text/markdown": [ "15" ], "text/plain": [ "[1] 15" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "n" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "fragment" } }, "source": [ "## which is equivallent to:" ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[1] 15\n" ] } ], "source": [ "print(n)" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "# Where is R Stored?\n", "\n", "It depends on your operating system.\n", "\n", "- On Windwows: `C:\\\\Program Files\\\\R\\\\R-3.3.3` \n", "- On Mac: `/Library/Frameworks/R.framework/Versions/3.3/Resources/library/`" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "'/Library/Frameworks/R.framework/Resources/library'" ], "text/latex": [ "'/Library/Frameworks/R.framework/Resources/library'" ], "text/markdown": [ "'/Library/Frameworks/R.framework/Resources/library'" ], "text/plain": [ "[1] \"/Library/Frameworks/R.framework/Resources/library\"" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# .Library is a character string giving the location of the default library\n", ".Library" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "'/Library/Frameworks/R.framework/Versions/3.2/Resources/library'" ], "text/latex": [ "'/Library/Frameworks/R.framework/Versions/3.2/Resources/library'" ], "text/markdown": [ "'/Library/Frameworks/R.framework/Versions/3.2/Resources/library'" ], "text/plain": [ "[1] \"/Library/Frameworks/R.framework/Versions/3.2/Resources/library\"" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# On this Mac: .libPaths is used for getting or setting the library trees \n", "# that R knows about (and hence uses when looking for packages)\n", ".libPaths()" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "# Today\n", "\n", "## Run R from R.app\n", "\n", "- Review `R` operators\n", "- Generate data\n", "- Manipulate `R` objects\n", "- Create graphics and plots" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "# Other tutorials\n", "\n", "Search engines will list a lot of R tutorials, here is just one:\n", "\n", "- http://www.cyclismo.org/tutorial/R/index.html\n", "\n", "Video tutorials also exist on YouTube, but at UW we also have access to Lynda.com video courses. \n", "\n", "- There are 3 courses for R listed at http://www.lynda.com/R-training-tutorials/1570-0.html\n", "\n", "You may need to login with your NetID to see/access these.\n", "\n", "- [Up and Running with R](http://www.lynda.com/R-tutorials/Up-Running-R/120612-2.html) 2h25m Beginner level\n", "- [R Statistics Essential Training](http://www.lynda.com/R-tutorials/R-Statistics-Essential-Training/142447-2.html) 5h59m\n", "- [Code Clinic: R](http://www.lynda.com/R-tutorials/Code-Clinic-R/372541-2.html) 3h24m" ] } ], "metadata": { "anaconda-cloud": {}, "celltoolbar": "Slideshow", "kernelspec": { "display_name": "Bash", "language": "bash", "name": "bash" }, "language_info": { "codemirror_mode": "shell", "file_extension": ".sh", "mimetype": "text/x-sh", "name": "bash" } }, "nbformat": 4, "nbformat_minor": 0 }