Welcome

These slides available at: https://arcus.github.io/first_steps_in_r_rstudio_skills_series/session_1.html

  • Use keyboard arrow keys to
    • advance ( → ) and
    • go back ( ← )
  • Type “s” to see speaker notes
  • Type “?” to see other keyboard shortcuts

About Arcus / Your Presenter

Arcus is an initiative by the Research Institute aimed at promoting data discovery and reuse and increasing research reproducibility.

Among the many teams in Arcus, I represent Arcus Education!

Arcus website which displays tools and services including cohort discovery, arcus archives, data catalog, education and training, scientific projects, and clinical data query.

A circular diagram showing five project phases, including Discover: explore available data, Plan: plan your research project, Collect: receive your data, Analyze: analyze data in an Arcus lab, and Share: contribute data to archives.

Arcus Education

Education website page that includes three sections titled Getting Started with Arcus, Learn Data Science Skills, and Curate Your Own Learning Experience.

Arcus education provides data science training to researchers …

(and often this is useful to non-researchers too!).

https://arcus.chop.edu/i-want-to/arcus-education

Email us!

First Steps in R and RStudio

Arcus Education provides “Skills Series” for the entire CHOP community.

This Skills Series is a 5-session series aimed at helping you take your first steps in R and RStudio!

  • Session 1: Review and Setup
  • Session 2: Projects and File Ingestion
  • Session 3: Exploring Data Visually, Using ggplot2
  • Session 4: Selecting Data Using dplyr
  • Session 5: Putting it All Together: Communicating Findings

Session 1 Itinerary

Review and Setup (see also: Demystifying R and RStudio)

  • Quick review of R, RStudio, and “literate statistical programming”
  • Posit.cloud: our environment for this course
  • Git and GitHub: Out of scope but very useful!
  • Your first Quarto Document

Goals:

  • Use Source and Visual views in RStudio to experiment with how markdown gets rendered into attractive and descriptive text
  • Create a new code chunk in a Quarto document
  • Run a code chunk in a Quarto document

R Vs RStudio

R logo.

RStudio logo

R Programming language for data analysis

RStudio Integrated development environment (IDE)

LSP Example (Quarto)

Text and R code with the title Ingest and Clean Data:Arcus 101.

In Literate Statistical Programming, we not only use code, but also describe what we do in human language, with things like headers, bullet points, and other formatting to make it easier for humans to make sense of the code.

Posit.Cloud (for learning only!)

You can use R and RStudio using online services like https://posit.cloud. Sign up for your ‘Cloud Free’ tier, it’s what we’ll use for this series.

Posit.cloud is a great place for learning or practice with public datasets, BUT is not a safe or compliant place to put your regulated data.

Posit.cloud page showing the plans, with Cloud Free tier indicated.

Posit.cloud page that reads sign up for Cloud Free.

02:00

Git and GitHub Desktop:

Version control allows you to track

  • What changed (the file name, and the line numbers and specific changes if it’s a text file)
  • When (date and time)
  • By whom (username / ID)
  • Why (the person changing will add a message)

(Out of scope today but useful!)

Creating a Project in Posit

Menu from the New Project button on Posit.cloud with an arrow indicating New Project from Git Repository

Form titled New Project from Git Repository that includes a fill in the blank titled URL of your Git Repository.

02:00

Create Your First Literate R Code!

This is what we’re going to do:

  • Create a new Quarto Document
  • Add a bit of description describing what you’re planning to do
  • Add an R language “Code Chunk” doing the thing (in our case, installing tidyverse and rmarkdown)
  • Run that code chunk to make sure it works
  • Save that Quarto document as setup.qmd in your Exercises folder.

Step 1: New Document

  • Go to File, New File, Quarto Document.
  • Give it the title “Setup” and click “Create”.
  • Try clicking on “Visual” and “Source” and scrolling up and down!
  • You might get a “Visual mode” pop up box – give it a read.

File Menu from Posit.cloud R environment, with Arrow indicating New File, Quarto Document.

New Quarto Document form which includes Title and Author.  Title is filled in with the word Setup and everything else is left as default.

01:00

Step 2: Add description

  • Remove the existing markdown and code
  • Start a new header (“Installing Packages”) with two hash marks (#)
  • Enter a blank line
  • Then type a description of installing packages

View of a short bit of Markdown that only includes a header line with two hash marks followed by 'Installing Packages' and then a line that reads 'We need to install some packages.'

01:00

Step 3: Add a Code Chunk

  • Position your cursor after your explanatory text
  • Hit enter to make sure there’s a blank line
  • Then use the green “+C” button to add a code chunk
  • Inside that code chunk, type this, exactly: install.packages(c("rmarkdown", "tidyverse"))

RStudio window with an arrow indicating the add new code chunk button at the top of the screen.

A new code chunk with one line of R code which reads install.packages(c("rmarkdown", "tidyverse")).

01:00

Step 4: Run Code Chunk

  • Use the green triangle (“Play” button) on the chunk to run the chunk
  • Look in the “Console” for output. It will be verbose, and take a while.
  • You’ll know it’s finished when the prompt > appears in the Console and the Stop sign disappears!

A code chunk with an arrow indicating the execute code chunk button.

A code chunk and the R console, with three indicators of the code being executed indicated with arrows.

00:30

Step 5: Save Document

  • Click on File, Save
  • Name your file “setup” (you don’t have to add “.qmd”, but you can!)
  • Save it inside the “exercises” folder
A Save File picker that shows the exercises folder.
00:30

Summary of Today

Today, you:

  • Learned about R and RStudio
  • Learned about Literate Statistical Programming
  • Signed up for (or logged into) Posit.cloud
  • Cloned (copied) our exercise files from GitHub into a new Project
  • Installed the tidyverse package into that Project

That’s a lot! Give yourselves a round of applause.

Q&A / Was This Effective?

We like to measure our effectiveness (and analyze it in R!)

Goals:

  • Use Source and Visual views in RStudio to experiment with how markdown gets rendered into attractive and descriptive text
  • Create a new code chunk in a Quarto document
  • Run a code chunk in a Quarto document

Next Session

Projects and File Ingestion

  • File systems can be challenging to navigate
  • Projects in RStudio
  • Installing and loading packages
  • Tabular data ingestion from .csv files
  • Functions in R