Mixing R and Python
Why Interoperability Matters
Sometimes a project has one useful Python tool, but the rest of the analysis is already in R. The reticulate package lets R call Python code and bring Python objects back into the R session. In this course, reticulate is awareness-level: you should know what it does and when it might be useful, but you are not expected to build a full mixed-language pipeline.
Minimal Demo
Run this in an R console or an R Quarto document if reticulate is available in your Codespace.
Health Data Example
The same idea works with the NHANES case-study CSV:
When To Use It
Use reticulate when:
- a small Python library solves a specific problem better than the R ecosystem;
- the rest of your report, tables, or dashboard are already in R;
- you can document the Python dependency clearly.
Avoid it when:
- a clean R solution already exists;
- mixing languages makes the project harder to reproduce;
- the Python step cannot run in a fresh Codespace.
Check Your Understanding
In one sentence, explain what object moves from Python back into R in the NHANES example above.