Repository navigation
lms: lint variable labels hardcoded in plot and table code - #190
Conversation
Ezra asked for a lint rule that keeps variable labels on the data, set once in preprocessing, rather than typed into labs(), xlab(), ylab() or a table's column names each time a plot or table is built. ggplot2 4.0 titles axes and legends from a column's label attribute, so labelled data needs no labs() call. Add lms::hardcoded_label_linter(), part of default_linters(nested_calls = TRUE), which flags a string literal (or c()/list()/paste0() of one) given as a variable's label in labs() (not title, subtitle, caption, tag or alt), xlab(), ylab(), a scale's name, a guide's title, kable(col.names =), DT::datatable(colnames =), gt::cols_label() and flextable::set_header_labels(). Document the pattern, including labs(dictionary =) for computed variables such as a histogram's count, in the Variable labels section. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019xfc9nB5JcJvBYV4BRx5Dq
plot(x, y, xlab = "...") and hist(x, xlab = "...") hardcode a label the same way labs() does; lds has about 90 such arguments. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019xfc9nB5JcJvBYV4BRx5Dq
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Cross-model review (agy, gemini-4-hydrogen-high) of head 9eebdac: SummaryPR #190 adds Findings
VerdictThe documentation, tests, namespace exports, and PR summary align well, but the XPath expression in VERDICT: NOT CLEAN Reviewed-Commit: 9eebdac Posted by Claude Code (AI agent) --- not written by a human. |
The agy review of 9eebdac found five XPath gaps: - named options of paste()/paste0()/glue() (sep, collapse, .sep) were read as label text; only unnamed arguments of formatting calls count; - a formatting call nested in c() or list() was missed; builders now nest up to three levels; - scale_discrete_manual() and the identity scales take the aesthetics first, so their first argument is no longer read as a name; - xlab/ylab/zlab keys inside c(), list(), set_variable_labels() and var_label() were flagged; those name labels, not axis titles; - the first positional argument was missed after a comment or a named argument, and gt's md() and html() were not checked. Each case has a test. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019xfc9nB5JcJvBYV4BRx5Dq
|
Claude finished review — View run I fetched PR #190 live just now. It is open, not a draft, and not merged, and its head is still Two things from this turn:
VerdictReady for merge Structured Review Data (JSON){
"schema_version": "1.1",
"reviewer": "claude",
"commit_sha": "12e7345962e18a6db549a8cfc3af5348bcda4945",
"verdict": "CLEAN",
"findings": [],
"detailed_assessment": "Ran lms/tests/testthat/test-hardcoded_label_linter.R at 12e7345: 45 passed, 0 failed, with warnings only from the missing cyclocomp package; the new unnamed-argument, nesting, md/html and label-container XPath logic behaves as documented.",
"holistic_assessment": "The commit narrows false positives and negatives in the opt-in linter without adding dependencies or changing scope; docs, Rd and tests agree, so the prior Ready for merge verdict still stands."
}Reviewed commit: 12e7345 |
Built to branch |
|
Cross-model review (agy, gemini-4-hydrogen-high) of head 12e7345: SummaryCommit
The tests in FindingsNone. VerdictAll five Round 1 XPath findings are resolved in VERDICT: CLEAN Reviewed-Commit: 12e7345 Posted by Claude Code (AI agent) --- not written by a human. |
|
Annotation dispositions for head 12e7345: Check runs 136158420703,136158311405:
Posted by Claude Code (AI agent) --- not written by a human. |
Requested by Ezra · project thread
Closes #189.
Why
Ezra (2026-11-19): "lint R code to enforce that labels are applied to data as attributes during preprocessing, not on the fly while constructing graphs, tables, etc", pointing at the lds splines lab's EDA, where
labs(x = "Wage (thousands of dollars)", y = "Number of workers")names the axes in the plotting code.ggplot2 4.0 titles each axis and legend from the mapped column's
labelattribute (checked with ggplot2 4.0.4:get_labs()returns the attribute), so data labelled once in preprocessing needs nolabs()call.What
lms/R/hardcoded_label_linter.R: newhardcoded_label_linter(), an XPath linter that flags a hardcoded label given as a variable's label in:labs(), excepttitle,subtitle,caption,tag,altandalt_insight(they describe the plot, not a variable); an inlinedictionaryis flagged, a named vector made in preprocessing is not;xlab(),ylab(), ascale_*()name(named, or the first positional argument wherever it sits; not forscale_discrete_manual()and the identity scales, whose first argument is the aesthetics), and aguide_*()title(named or first positional);xlab,ylaborzlabargument of any call exceptc(),list(),set_variable_labels()andvar_label(), such as base graphics'plot()andhist()(lds has about 90);kable(col.names =),datatable(colnames =),gt::cols_label()andflextable::set_header_labels().A value is hardcoded when it is a string literal; a
c()orlist()with one among its values; or apaste(),paste0(),sprintf(),glue(),md()orhtml()with one among its unnamed arguments (named options such assepandcollapseare not label text). These builders nest up to three calls deep.A label read from the data (
labelled::var_label(df[["x"]])),expression()andNULLpass.lms/R/default_linters.R,lms/NAMESPACE,lms/man/*.Rd(roxygen2 output): the linter joins thenested_calls = TRUEgroup, besideggplot_args_linter().lms/tests/testthat/test-hardcoded_label_linter.R: positive and negative cases for each function family, the plot-description exemptions, base graphics, the dictionary case, each case from the agy review below, and membership indefault_linters().lms/README.md: lists the sixth linter.chapters/coding-practices/documenting-code.qmd: new "Read labels from the data in plots and tables" subsection under Variable labels, with the preprocessing pattern, a counter-example,labs(dictionary =)for a computed variable such as a histogram'scount, andkable(col.names =)fromlabelled::var_label(..., null_action = "fill").Review follow-up
12e7345 fixes the five XPath gaps in the agy review of 9eebdac: named
sep/collapse/.sepoptions, builders nested inc()/list(),scale_discrete_manual(),xlabkeys in label containers, and a first positional argument after a comment or a named argument, plusmd()/html().Rollout
On the current lds subfiles the first version of the linter reported 605 lints in 290 files, so there is no sweep:
each repository's
lint-changed-linesworkflow lints only added or edited lines, and the rule takes effect there once itslms-refmoves to this PR's merge commit.The splines lab example gets its own small lds PR after that bump.
Checks run
testthat::test_local("lms"): 192 pass, 0 fail.lintr::lint()with the repo's.lintr.Ron the changed R files: no lints.typoson the changed files: clean.quarto render chapters/coding-practices.qmd --to html: renders; read the new subsection in the output.Annotations
The annotation gate reported 2 annotations on 9eebdac, both notices, and both unrelated to this diff:
build / build: "SUBMODULES_TOKEN is empty; cloning submodules anonymously". Themacrossubmodule is public, so the anonymous clone works.review / claude-review: "Skipping element-level diff highlighting: 798 old / 808 new candidate elements exceed the 500-element cap". This is a limit of the review's render diff, not a defect.Note: under a C locale, lintr's
xml_nodes_to_lints()errors on a flagged string with a non-ASCII character (such as"Log-odds η"), because columns are counted in bytes; under a UTF-8 locale, as on CI, it works.🤖 Generated with Claude Code
https://claude.ai/code/session_019xfc9nB5JcJvBYV4BRx5Dq