Orientation

A Slower Introduction to R

Yea-Hung Chen, PhD, MS

UCSF Library

Thursday, October 9, 2025

Pitch

Pitch

  • there are a lot of resources out there for learning R
  • why should you consider participating in this workshop series?

Pitch

  • slower in pace 🐢 and less technical, compared to other resources
  • oriented towards real-world tasks
  • uses real data from health sciences

Pitch

  • I have over 10 years of experience teaching R to the UCSF community
  • over that period of time, I have introduced R to several hundred UCSF learners
  • the prior iteration of this series (earlier this year) was well attended and well received

Expectations

Format

  • mini lectures, with hands-on exercises interspersed
  • roughly speaking:
    • lectures = watch and listen
    • hands-on exercises = practice
  • optional take-home practice (homework)

Participation

Tip

Please ask questions and participate!

  • you can simply shout out

Participation

Caution

Please be mindful about seeking help during the mini lectures.

  • if you’re trying things out during the mini lectures and get stuck, please wait until the next exercise portion to reach out for help
  • similarly, I want the chat to be a useful space but I also don’t want it to be a distraction during the mini lectures

Learning from each other

Tip

Try to learn from each other.

  • for example, if you know other people who are participating in the series, you might even consider sitting together sometimes!

Even more practice

Tip

Try to find other ways to practice R.

  • for example, if you are involved in an existing project that uses Stata, you can try to reproduce portions of the work

Scope

Caution

This is not a statistics or biostatistics course.

  • I’ll focus on R rather than underlying methods
  • please do seek out additional training in those areas if you think you could strengthen your understanding

What and why

What is statistical software?

  • statistical software is software for conducting statistical analysis
  • popular examples include: R, Stata, SAS, and IBM SPSS
  • each software program often has its own programming language
  • the language allows you to write instructions to your computer
  • code is useful because it supports transparency and reproducibility

What is R?

  • R is a popular statistical software program
  • the term also refers to the programming language

What is R?

  • R is open source, meaning that the underlying technology is publicly available online and that the software can be freely shared
  • R is not made by any one private company, but rather by a community of individual contributors, from a variety of organizations
  • there are various online forums and other resources
  • R includes few icons or menus

Packages

  • there are many (well over 20,000) add-on packages available for R
  • these add extra features, such as:
    • specific methods
    • data visualization
    • mapping and GIS (geographic information system)
    • games

Packages

The wordler package adds a Wordle-like game.

Base R and tidyverse

  • there are several popular packages under the tidyverse umbrella
  • this has led to two primary ways of doing things in R:
    • base R: original ways of doing things
    • tidyverse: newer ways of doing things, via packages in the tidyverse umbrella

Base R and tidyverse

  • mostly, I just want you to be aware of this split as you learn R
  • this workshop series will focus on base R, but we will talk about tidyverse packages in two sessions:
    • Session 5: ggplot2
    • Session 7: tidyr

Why use R?

  • it is extremely powerful
  • it is extremely popular
  • it is free of cost

What is RStudio?

  • RStudio is an add-on interface for R, adding icons, menus, and many other features
  • it was first released in 2011

What is RStudio?

  • RStudio adds numerous helpful features to R, including:
    • suggestions
    • syntax highlighting (color coding)
    • a script window (we’ll talk about this later)
  • but to be clear, RStudio does not allow for graphical operation of R (such as through drop-down menus)

Deep breaths

Deep breaths

The panic room can only fit three. Who’s the least panicked?”

Embrace the process

  • I encourage you to try to embrace the learning process 🌱
  • and celebrate your day-to-day success 🎉

You’ve done similar things

  • learning R is in many ways similar to developing other skills, and you can draw from that experience:
    • learning R is similar to learning a human language
    • learning R is similar to learning how to cook 🍳
    • and so forth…

You’ve done similar things

  • learning and using R relies on core skills:
    • problem solving and troubleshooting
    • pattern recognition and attention to detail
  • you’ve had to use these skills before
  • and, you will benefit from these skills in the future

Tips

Problem solving and troubleshooting

Tip

Focus on problem solving rather than memorization.

  • I like this opinion piece
  • error messages are inevitable
  • and, it is inevitable that something might not work
  • try to troubleshoot

Pattern recognition and attention to detail

Tip

Try to recognize patterns and be detail-oriented.

  • carefully replicate patterns
  • watch out for typos

Pattern recognition and attention to detail

  • this is incorrect because it does not exactly replicate the pattern:
prop.table(ii$hs,ii$smoking,margin=1)
  • this is correct:
prop.table(table(ii$hs,ii$smoking),margin=1)

Pattern recognition and attention to detail

  • this is incorrect because it includes a typo:
nhanes<-read.csv('nhanes.cvs')
  • this is correct:
nhanes<-read.csv('nhanes.csv')

Multiple solutions

Tip

Be aware that there may often be multiple solutions to a problem, and be open to exploring them.

  • in R, there is often more than one way of doing something
  • this is very different than other statistical software like Stata or SAS

Multiple solutions

  • some solutions may be more “elegant” than others
  • some solutions may also be more computationally efficient than others (take less time to run on your computer)

Fundamentals

Tip

Be patient as you learn fundamentals and think about how you can piece skills together.

  • R has many fundamentals
  • an analogy is learning how to cook:
    • in a professional cooking school, you might spend weeks practicing specific skills