first steps in rstudio

6
First Steps in RStudio Prof. Dr. Jan Kirenz

Upload: prof-dr-jan-kirenz

Post on 16-Apr-2017

878 views

Category:

Data & Analytics


0 download

TRANSCRIPT

First Steps in RStudioProf. Dr. Jan Kirenz

Prof. Dr. Jan Kirenz

First Steps in RStudio

l R code editor

l The top left window is where you'llprobably do most of your work.

l That's the R code editor allowingyou to create a file with multiple linesof R code. There you‘ll write yourstatistical commands.

l For example, enter 2+2 and click on the „run“ button (see arrow)

l You can use the hashtag character, #, for adding comments. R will not run anything that follows a hashtagon a line.

6

RStudio

Source: Machlis, S. (2013). Get started with this popular programming language. Terieved from URL http://www.computerworld.com/article/2497143/business-intelligence/business-intelligence-beginner-s-guide-to-r-introduction.html

Prof. Dr. Jan Kirenz

First Steps in RStudio

l Interactive Console

l Bottom left is the interactive consolewhere you can type in R statementsone line at a time.

l Any lines of code that are run fromthe editor window also appear in theconsole.

l The console is R's way of telling youwhat it's doing.

l For example, let's use R like a calculator: try typing in 1+1 in theinteractive console.

7

RStudio

Source: Machlis, S. (2013). Get started with this popular programming language. Terieved from URL http://www.computerworld.com/article/2497143/business-intelligence/business-intelligence-beginner-s-guide-to-r-introduction.html

Prof. Dr. Jan Kirenz

First Steps in RStudio

l Workspace

l The top right window shows yourworkspace, which includes a list ofobjects currently in memory.

l There's also a history tab with a listof your prior commands; what'shandy there is that you can selectone, some or all of those lines ofcode and one-click to send themeither to the console or to whateverfile is active in your code editor

8

RStudio

Source: Machlis, S. (2013). Get started with this popular programming language. Terieved from URL http://www.computerworld.com/article/2497143/business-intelligence/business-intelligence-beginner-s-guide-to-r-introduction.html

Prof. Dr. Jan Kirenz

First Steps in RStudio

l Plots

l The window at bottom right shows a plot if you've created a datavisualization with your R code.

l There's a history of previous plotsand an option to export a plot to an image file or PDF.

l This window also shows externalpackages (R extensions) that areavailable on your system, files in your working directory and help fileswhen called from the console.

9

RStudio

Source: Machlis, S. (2013). Get started with this popular programming language. Terieved from URL http://www.computerworld.com/article/2497143/business-intelligence/business-intelligence-beginner-s-guide-to-r-introduction.html

Prof. Dr. Jan Kirenz

First Steps in RStudio

l Installing Packages

l R only includes a basic set of functions. It can do much more than this, but not everybodyneeds everything so we instead make some functions available via packages.

l You can easily install packages from within R if you know the name of the packages.

l As an example, we are going to install the packages rafalib and downloader. Type thiscommands into the workspace: > install.packages(“ggplot2")

l We can then load the package into our R sessions using the library function: > library(ggplot2)

l From now on you will see that we sometimes load packages without installing them. This isbecause once you install the package, it remains in place and only needs to be loaded withlibrary. If you try to load a package and get an error, it probably means you need to install itfirst.

10

RStudio

Source: Irizarry, R. A. & Love, M. I. (2015). Data Analysis for the Life Sciences. Retrieved from URL https://leanpub.com/dataanalysisforthelifesciences