Skip to content

Modernize pipe operator and recode() usage - #149

Merged
jt14den merged 2 commits into
mainfrom
modernize/native-pipe-and-case-match
Aug 23, 2026
Merged

Modernize pipe operator and recode() usage#149
jt14den merged 2 commits into
mainfrom
modernize/native-pipe-and-case-match

Conversation

@jt14den

@jt14den jt14den commented Aug 8, 2026

Copy link
Copy Markdown
Member

Summary

  • Converts %>% to the native pipe |> throughout episodes 1, 3, 4, and 5, matching the current tidyverse style guide recommendation for R 4.1+ (this lesson already requires R 4.5+ per renv.lock).
  • Replaces dplyr::recode(), which is marked [Superseded] on the current dplyr reference page, with case_match() in episodes 3 and 5. Each conversion includes an explicit .default argument to preserve recode()'s pass-through behavior for any value not in the mapping list, since case_match() returns NA for unmatched values by default.
  • Updates the accompanying prose (objectives, section headings, exercise text, keypoints) to match.

Test plan

  • sandpaper::validate_lesson() passes with no errors
  • All four modified episodes knit cleanly from a fresh session with no rendered R errors
  • Verified case_match() output is byte-identical to recode() output when run against the actual episodes/data/books.csv for both subCollection and format
  • Confirmed every raw code value in the dataset is covered by the mapping list, so .default is a safety net rather than currently masking a data problem
  • Would appreciate a second read on the case_match() conversions in episode 3 (lines ~203, ~221, ~551) and episode 5 (lines ~43, ~59, ~156) before merge, since this is a real behavioral change to double-check, not just a rename

Convert %>% to the native pipe |> throughout episodes 1, 3, 4, and 5,
matching the current tidyverse style guide recommendation for R 4.1+
(this lesson already requires R 4.5+).

Replace dplyr::recode() (superseded) with case_match() in episodes 3
and 5, including an explicit .default to preserve recode()'s
pass-through behavior for values not in the mapping list. Verified
case_match() output is identical to recode() output on the actual
dataset (episodes/data/books.csv), and that .default isn't currently
masking any data issue since every raw code value is covered by the
mapping.

Updated accompanying prose (objectives, headings, exercise text,
keypoints) to match.

Verified: sandpaper::validate_lesson() passes, and all four episodes
knit cleanly from a fresh session with no rendered errors.
@github-actions

github-actions Bot commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Thank you!

Thank you for your pull request 😃

🤖 This automated message can help you check the rendered files in your submission for clarity. If you have any questions, please feel free to open an issue in {sandpaper}.

If you have files that automatically render output (e.g. R Markdown), then you should check for the following:

  • 🎯 correct output
  • 🖼️ correct figures
  • ❓ new warnings
  • ‼️ new errors

Rendered Changes

🔍 Inspect the changes: https://github.com/LibraryCarpentry/lc-r/compare/md-outputs..md-outputs-PR-149

The following changes were observed in the rendered markdown documents:

 01-intro-to-r.md                                   |   10 +-
 02-starting-with-data.md                           |    2 +-
 03-data-cleaning-and-transformation.md             |  173 +-
 04-data-viz-ggplot.md                              |   18 +-
 05-reproducible-reports.md                         |    6 +-
 config.yaml (gone)                                 |   86 -
 ...t-rendered-boxplot-exercise-subcollection-1.png |  Bin 49562 -> 49340 bytes
 ...a-viz-ggplot-rendered-boxplot-with-points-1.png |  Bin 42909 -> 42953 bytes
 ...data-viz-ggplot-rendered-unnamed-chunk-14-1.png |  Bin 39625 -> 39407 bytes
 fig/04-data-viz-ggplot-rendered-violin-plot-1.png  |  Bin 38570 -> 38763 bytes
 ...oducible-reports-rendered-plot-high-usage-1.png |  Bin 46952 -> 47007 bytes
 md5sum.txt                                         |   32 +-
 renv.lock (gone)                                   | 3962 --------------------
 13 files changed, 130 insertions(+), 4159 deletions(-)
What does this mean?

If you have source files that require output and figures to be generated (e.g. R Markdown), then it is important to make sure the generated figures and output are reproducible.

This output provides a way for you to inspect the output in a diff-friendly manner so that it's easy to see the changes that occur due to new software versions or randomisation.

⏱️ Updated at 2026-08-23 01:42:00 +0000

@nickyjgarland

Copy link
Copy Markdown
Contributor

The changes in syntax all seem fine but while checking case_match() as a replacement I noted in the documentation that this function was also depreciated. Is there a benefit of using this function or should we switch to a suggested alternative such as recode_values()?

@jt14den
jt14den merged commit 8bd2b22 into main Aug 23, 2026
5 checks passed
@jt14den
jt14den deleted the modernize/native-pipe-and-case-match branch August 23, 2026 01:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants