Intermediate R programming II

Objective

Learners will learn how to make their R code more reproducible using for loops and the apply family of functions.

Installation & materials

  1. Slides
  2. Data Carpentry for Biologists for loop lecture
  3. Data Carpentry for Biologists iteration without loops lecture?

Review

Can share their plans for apply skills to their research. Lead optional discussion on when to use base R vs. tidyverse packages/functions.

Modifications

  • For for loops lecture:
    • At “Do Tasks 3-4…”, do “Basic For Loop” exercises #2 & #3
    • Skip sections “Looping over multiple values” and “Looping with functions”
    • Stop at “Looping over files” due to zip download issues
  • For apply lecture:
    • Do “Size Estimates With Maximum” exercise
    • Do “Size Estimates Vectorized 2” exercise
    • Stop after first section in “Other apply functions (optional)” section

Teaching notes

  • Create new R script for these materials. Put script into repro-DS-workshop repo
  • Emphasize using for loops using index or non-index methods. Index can be useful for reducing memory use and for storing results
  • If time, demonstrate combining if and for

Homework

Identify a script from a research project that could benefit from a for loop, apply, conditional, or function.

Citation

BibTeX citation:
@online{scott2024,
  author = {Scott, Eric and Diaz, Renata and Guo, Jessica and Riemer,
    Kristina},
  title = {Intermediate {R} Programming {II}},
  date = {2024},
  url = {https://cct-datascience.github.io/repro-data-sci/lessons/9-intermediate-r-2/notes.html},
  doi = {10.5281/zenodo.8411612},
  langid = {en}
}
For attribution, please cite this work as:
Scott, Eric, Renata Diaz, Jessica Guo, and Kristina Riemer. 2024. “Intermediate R Programming II.” Reproducibility & Data Science in R. 2024. https://doi.org/10.5281/zenodo.8411612.