Working with R – RStudio

RStudio is an Integrated Development Environment (IDE) for R and it helps you:

  • write code - makes suggestions
  • view the output of your code, including plots
  • find errors
  • manage files
  • view documentation

RStudio logo

[source]

RStudio used to be the name of a company that is now called Posit.

RStudio

First it is important to be familiar with the layout. When you first open RStudio, you will see 3 panes.

When RStudio is first opened you will see 3 panes

Hidden Pane

To save a copy of your code. You must open a file first - this will open a 4th pane. These files include Scripts or what are called R Markdown files.

Hidden Pane

You will see a popup that you can just say “OK” to for now.

Hidden Pane

Nice! now we have a place to save code! This is where we will mostly be working.

Working with R in R Studio - 2 major panes:

  1. The Source/Editor:

    • Top by default
    • saves your code
  2. The R Console:

    • Bottom by default
    • Calculator
    • Place to try things out, then add to your editor
    • doesn’t save your code

RStudio

Super useful “cheatsheet”: LINK

RStudio

R Markdown files look different form scripts

It will look like this with text in it.

RStudio layout

Scripts will just be empty

Scripts and R Markdown

Although people will use scripts often, and they are good for more programmatic purposes, we generally don’t recommend them for Public Health Researchers.

For data analyses, R Markdown files are generally superior because they allow you to check your code and write more info about your code.

Workspace/Environment