Skip to content

Use dplyr filter() and select() to subset datasets in R, not base [] #111

Closed

Description

@d-morrison

Ezra, 2026-11-10 (psc: message): "psc: let's use dplyr's filter() and select() to subset datasets in R, instead of base [] (for example https://morrison-lab.github.io/lds/chapters/discriminant-analysis.html#sol-lab-knn-split)"

Rule

Subset a data frame or tibble with dplyr::filter() (rows) and dplyr::select() (columns), and extract one column with dplyr::pull(), never with base df[i, j], df[i, ], df[, j] or df[df$x > 0, ].

Work

  • Add the rule to chapters/coding-style/tidyverse-replacements.qmd.
  • Add a deny-form check to lms that flags x[i, ] and x[, j] (a [ call with an empty argument), so lint-changed-lines catches it. Matrices keep base [] with # nolint.
  • Mirror the rule in ai-config's shared/coding/tidy-code.md (Morrison-Lab/ai-config tracking issue to follow).
  • Apply it to the cited lds example, and list the other base-[] sites in lds R code (separate lds issues; no sweep).

Filed by Claude Code (AI agent) on Ezra's behalf.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions