Python vs. R
The Course Position
R remains the core language for required analysis in this course. Python is introduced so you can read short Python examples, translate small workflows with AI assistance, and recognize when Python may be useful in a health data project.
You are not choosing one language forever. You are learning how to move carefully between them.
Strengths At A Glance
Think in terms of your goal, not package names:
| If your goal is… | Better default | Why |
|---|---|---|
| Summarise a health dataset and write it up (like our NHANES work) | R | The dplyr steps you already know plus Quarto take you from raw CSV to a finished report in one place |
| Make clear charts for a report or slides | R | ggplot2 charts drop straight into your Quarto documents |
| Read example code you found online or got from another team | Either | A lot of shared data code is written in Python; this week teaches you to read it without abandoning R |
| Write a small reusable helper function | Either | Both languages do this well — you practice both in Week 5 |
| Build machine-learning models or software that runs behind a website | Python | Most of that tooling is built Python-first; it is beyond the scope of this course |
When in doubt in this course, use R. Reach for Python only when an instruction, or your project, clearly calls for it.
Notebooks vs. Scripts
- A notebook (
.ipynb) is useful for exploration, teaching, and step-by-step AI translation checks. - A script (
.py) is useful for reusable functions and automation. - A Quarto document (
.qmd) is best when your analysis needs narrative, code, figures, citations, and a rendered final product.
Check Your Understanding
Write two sentences:
- One task where you would stay in R.
- One task where Python might be worth considering.