Skip to content

Dev - #106

Merged
vertesy merged 9 commits into
mainfrom
dev
Aug 31, 2026
Merged

Dev#106
vertesy merged 9 commits into
mainfrom
dev

Conversation

@vertesy

@vertesy vertesy commented Aug 31, 2026

Copy link
Copy Markdown
Owner

No description provided.

vertesy and others added 7 commits August 27, 2026 01:12
All three contained the identical no-op line:

  if (is.numeric(col) & col < length(vars)) col <- col

so a numeric `col` was never interpreted at all. It fell through to `fill <- col`
and reached ggpubr as a bare number, which ggplot2 reads as a base R colour
code - qboxplot(tg, col = 2) produced #DF536B. That matched neither the
documented behaviour ("the index or name of the column") nor qbarplot() and
qhistogram(), where a number is a palette index.

PR #87 previously proposed reading it as a *column* index; that was closed. Per
the design discussion, a number is now a *palette* index everywhere, which is
also what the Q1 answer specified.

Adds one internal resolver, .resolveColToFill(), used by all three functions so
the semantics cannot drift apart again:

  1. a character matching a column name -> returned unchanged, so ggpubr groups
     by that column and colours it through palette_use (unchanged behaviour)
  2. a single positive whole number, or a digit-only string such as "2" ->
     looked up in palette_use
  3. anything else -> returned unchanged and used as a literal colour
     (unchanged behaviour)

The index detection reuses the hardened predicate from the edit to #97:
length 1, non-NA, >= 1, and whole-number numeric or digit-only string. The
palette is sized to cover the requested index so pal[i] cannot yield NA.

qboxplot needed one extra detail: by the time `col` is resolved, its
`palette_use` has already been overwritten with the recycled `fill` colour, so
the resolver is given `palette_use_bac` (the palette as requested) instead.
Without this, every index resolved to the fill colour ("gold").

Behaviour change, deliberate and documented: col = <number> now yields a
palette colour rather than a base R colour code. col = NULL, column names, and
literal colours are all unchanged.

Verified for all three functions across col = NULL, 1, 2, 5, "2", a column
name, and a literal colour, plus a custom palette vector and list input. All
three now return identical colours for identical input.
…)[1] default

No behaviour change - documentation and clarity only.

The default was written as `col = c(NULL, 3)[1]`, which reads as "NULL or 3,
take the first" but always evaluates to 3, because c() silently drops NULL.
Compare qqSave's `plot_on_page = list(FALSE, "A4p", ...)[[1]]`, where the
list() form does correctly preserve the alternatives. Replaced with a plain
`col = 3` plus a comment recording what the old idiom actually did, so nobody
re-derives NULL as a supported option.

The roxygen said only "Color of the plot", which hid three things that cost me
time during the color audit:
  - `col` is passed straight to ggpubr::ggscatter(color = ), with no
    interpretation by ggExpress at all;
  - a number here is therefore a base R colour code (the default 3 is green),
    NOT an index into palette_use as in qbarplot() and qhistogram();
  - colouring by a *numeric* column fails outright ("Continuous value supplied
    to a discrete scale"), because palette_use is a discrete scale; only
    discrete columns work.

Deliberately NOT changed: the numeric semantics. Making a number a palette
index here would be consistent with the rest of the package, but 3 is also the
default, so it would change the point colour of every existing qscatter call
from green to palette colour 3. That needs a decision rather than a silent
change.

Verified unchanged: default -> colour 3, col = 2 -> colour 2, col = "red" ->
red.
q32vA4_grid_plot() and qA4_grid_plot() defaulted h/w to hA4*scale and
wA4*scale, but hA4/wA4 were never defined anywhere in the package,
erroring on any default call. Added them as real parameters (11.69 x
8.27 inches, matching the A4 dimensions used elsewhere in this file).
Also fixed the h/w roxygen descriptions, which had hA4/wA4 swapped.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Per feedback: hA4/wA4 are meant to be optional background variables a
caller can predefine (e.g. in their session) to change plot defaults
package-wide. Adding them as new function parameters broke positional
argument order and didn't support that workflow. Use
get0("hA4", ifnotfound = 11.69) / get0("wA4", ifnotfound = 8.27)
directly in the h/w defaults instead, in q32vA4_grid_plot() and
qA4_grid_plot(). Regenerate the corresponding .Rd files and bump the
package version per AGENTS.md.

Co-authored-by: Abel Vertesy <5101911+vertesy@users.noreply.github.com>
Fix undefined hA4/wA4 constants in q32vA4_grid_plot()/qA4_grid_plot()
Document qscatter's col semantics and remove the misleading c(NULL, 3)[1] default
Make numeric col a palette index in qboxplot, qviolin and qstripchart

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3467c91a98

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread R/ggExpress.R
} else {
palette_use
}
return(pal[col_i])

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Validate custom palette indexes before returning a color

Problem: .resolveColToFill() returns NA when col exceeds the length of a custom palette_use, so the plot can lose its fill or fail inside ggpubr. Trigger: This happens with calls such as qviolin(data, col = 3, palette_use = c("red", "blue")), even though the documentation accepts any positive palette index. Fix: Add the required compact input assertion and either reject out-of-range indexes or define how custom palettes should be extended.

AGENTS.md reference: AGENTS.md:L13-L13

Useful? React with 👍 / 👎.

@vertesy

vertesy commented Aug 31, 2026

Copy link
Copy Markdown
Owner Author

@claude

could you please address the codex comment:

"Validate custom palette indexes before returning a color

Problem: .resolveColToFill() returns NA when col exceeds the length of a custom palette_use, so the plot can lose its fill or fail inside ggpubr. Trigger: This happens with calls such as qviolin(data, col = 3, palette_use = c("red", "blue")), even though the documentation accepts any positive palette index. Fix: Add the required compact input assertion and either reject out-of-range indexes or define how custom palettes should be extended."

@claude

claude Bot commented Aug 31, 2026 •

Copy link
Copy Markdown

Claude finished @vertesy's task in 1m 53s —— View job


Addressed the Codex review comment

  • Read codex review comment and locate .resolveColToFill() in R/ggExpress.R
  • Add compact input assertion + out-of-range palette index handling
  • Regenerate docs / check roxygen example still valid
  • Commit and push fix

Fix (R/ggExpress.R:2759):

  • Added the required compact input assertion at the top of .resolveColToFill() (stopifnot on col, vars, palette_use), per AGENTS.md.
  • Named palettes (e.g. "jco") are still auto-regenerated with ggpubr::get_palette() to cover any requested index — unchanged behavior.
  • Custom color vectors (e.g. palette_use = c("red", "blue")) can't be extended, so col_i <= length(palette_use) is now enforced via stopifnot. qviolin(data, col = 3, palette_use = c("red", "blue")) now throws a clear error ("col index exceeds the number of colors in the custom palette_use.") instead of silently returning NA and losing the fill downstream in ggpubr.
  • Mirrored the updated @description in man/dot-resolveColToFill.Rd to explain the new error behavior.

Note: R is not available in this sandbox, so I could not run roxygen2::roxygenise(), devtools::check(), or execute the function to verify at runtime. I manually edited the .Rd file to match the roxygen source; the logic was verified by careful inspection. If CI runs R CMD check or tests, please confirm they pass — happy to fix anything that surfaces.

Pushed as commit 3ba9d24 on branch dev.
|

github-actions Bot and others added 2 commits August 31, 2026 20:40
Previously a col index beyond the length of a custom palette_use vector
(e.g. qviolin(data, col = 3, palette_use = c("red","blue"))) silently
resolved to NA. Named palettes are still auto-regenerated to cover the
requested index, but custom vectors cannot be extended, so an
out-of-range index now throws a clear error instead.

Co-authored-by: Abel Vertesy <5101911+vertesy@users.noreply.github.com>
@vertesy
vertesy merged commit 79b9a56 into main Aug 31, 2026
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.

1 participant