short introduction to rstudiofelixhaass.de/files/rstudio presentation.pdf · short introduction to...

9
Short Introduction to RStudio Felix Haass GIGA German Institute of Global and Area Studies University of Greifswald Prepared for the ECPR Summer School 2015 Multiple Regression Analysis Prof. Dr. Bernhard Kittel July 26, 2015

Upload: others

Post on 14-Oct-2020

10 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Short Introduction to RStudiofelixhaass.de/files/RStudio Presentation.pdf · Short Introduction to RStudio Felix Haass GIGA German Institute of Global and Area Studies University

Short Introduction to RStudio

Felix Haass

GIGA German Institute of Global and Area StudiesUniversity of Greifswald

Prepared for the ECPR Summer School 2015Multiple Regression AnalysisProf. Dr. Bernhard Kittel

July 26, 2015

Page 2: Short Introduction to RStudiofelixhaass.de/files/RStudio Presentation.pdf · Short Introduction to RStudio Felix Haass GIGA German Institute of Global and Area Studies University

The RStudio Environment

Page 3: Short Introduction to RStudiofelixhaass.de/files/RStudio Presentation.pdf · Short Introduction to RStudio Felix Haass GIGA German Institute of Global and Area Studies University

The Editor - What it does

This is where you:

1. Write your scripts (but notnecessarily all your code!)

2. View your data (type inconsole: View(data))

3. Write reports or createpresentations (Markdown)

Page 4: Short Introduction to RStudiofelixhaass.de/files/RStudio Presentation.pdf · Short Introduction to RStudio Felix Haass GIGA German Institute of Global and Area Studies University

The Editor - How to use it

Useful tips for using the RStudio editor

1. Execute code: Select code chunk &Ctrl+Enter

I Ctrl+S+Enter executesentire script

2. Shortcut: Ctrl+1

I focuses cursor on editorwindow

I useful if you switch oftenbetween console and editor

3. Code completion: Press Tab

4. Warns if your code has typos:

Page 5: Short Introduction to RStudiofelixhaass.de/files/RStudio Presentation.pdf · Short Introduction to RStudio Felix Haass GIGA German Institute of Global and Area Studies University

The Data Viewer

Usually it’s a good idea toinspect your data visually.This is what the data vieweris for.

1. Filter: toggle filter foreach variable directly inthe data viewer

2. Search: search dataframe for string /number

3. Click on variable nameto sort data framebased on that variable(descending / ascending/ alphabetical)

Page 6: Short Introduction to RStudiofelixhaass.de/files/RStudio Presentation.pdf · Short Introduction to RStudio Felix Haass GIGA German Institute of Global and Area Studies University

The Console

1. Write your step-by-stepcode. If it works →copy it to source editor!

2. Up (Arrow): lastcommand

3. Ctrl+Up: popup codehistory. Tip: starttyping command &Ctrl+Up to see recentinstances of command.Can save lots of time!

4. Focus cursor onconsole: Ctrl+2

Page 7: Short Introduction to RStudiofelixhaass.de/files/RStudio Presentation.pdf · Short Introduction to RStudio Felix Haass GIGA German Institute of Global and Area Studies University

Environment & History

Environment

1. See which objects are inyour workspace (WS canget crowded sometimes;this is where theEnvironment panelbecomes useful)

2. Clear global environmentwith rm(list = ls())

3. Click on object to view itin the data viewer

The History

1. See what you did.(Always good idea)

2. If it worked → copy it tosource or console

Page 8: Short Introduction to RStudiofelixhaass.de/files/RStudio Presentation.pdf · Short Introduction to RStudio Felix Haass GIGA German Institute of Global and Area Studies University

Plot / Help / Files

Plot

1. Look at your plots

2. Export them (better to usecode for this, though!Replication!)

Help

1. help(command) opens thiswindow

Files (no screenshot)

1. Open files / scripts

2. Point+Click to set workingdirectory. Faster:Ctrl+Shift+H

Packages (no screenshot)

1. Manage your packages

2. Update & install packages

Page 9: Short Introduction to RStudiofelixhaass.de/files/RStudio Presentation.pdf · Short Introduction to RStudio Felix Haass GIGA German Institute of Global and Area Studies University

We’ve only scratched the surface...

General advice

I Alt+Shift+K displays keyboard shortcuts

I Trouble? R’s emergency center ishttp://stackoverflow.com

Further functionality

I RStudio Projects: see here

I R Markdown: Write reports & presentation withPDF, .docx, or HTML output directly in R:http://rmarkdown.rstudio.com/

I Diagrams:http://rich-iannone.github.io/DiagrammeR/

I Version control with GitHub, see e.g. here, hereor here

R Markdown

Diagrams in RStudio