Skip to content

feat: add tinyplot.array() method - #746

Merged
grantmcdermott merged 8 commits into
mainfrom
array-method
Sep 27, 2026
Merged

grantmcdermott merged 8 commits into
mainfrom
array-method

Conversation

@grantmcdermott

Copy link
Copy Markdown
Owner

Closes #548.

Summary

  • New tinyplot.array() method for (unclassed) arrays with up to 4 dimensions:
    • 1D → index plot (treated as a 1-column matrix)
    • 2D → already dispatches to tinyplot.matrix()
    • 3D → facet wrap by the 3rd dimension
    • 4D → facet grid (3rd dim = rows, 4th = cols)
    • 5D+ → informative error
    • names(dimnames(x)), if present, supply axis/legend/facet titles (works with facet.args = list(prefix = TRUE))
    • "tile"/"heatmap" types lay out each 2D slice as a grid, as for matrices
  • tinyplot.matrix() is refactored onto a shared internal array_plot() helper. Existing matrix snapshots are unchanged.
  • Fix (Incompatible with arrays #548 reprex): 1-row/1-column array inputs are dropped to vectors in sanitize_datapoints(), so tinyplot(1:10, array(1:10, c(1, 10))) now works like plot().
  • Fix: two-sided facet formulas with the default method (tinyplot(x, y, facet = a ~ b, data = dat)) errored because data was never stored in settings, so sanitize_facet() resolved it to utils::data. This also removes dead facet.args code in that branch, since the grid layout is read from the facet_grid attribute downstream.

Notes

  • "table" objects (HairEyeColor, Titanic, ...) don't dispatch here because of their class attribute. Per the discussion in Incompatible with arrays #548, contingency tables probably want different defaults (barplot/spineplot) and a separate tinyplot.table() method.
  • Multi-column matrix y passed to the default method (e.g. tinyplot(x, Y)) is still out of scope.

Tests

New inst/tinytest/test-array.R (6 snapshots + error checks). Full suite passes locally on Linux: 832 results OK.

Add a tinyplot.array() method for arrays with up to four dimensions.
The first two dimensions follow the tinyplot.matrix() conventions; the
third maps to a facet wrap and a fourth to a facet grid. The matrix
method is refactored onto a shared internal array_plot() helper.

Also fix two related bugs:
- Drop degenerate dimensions (1-row/1-column arrays) in
  sanitize_datapoints(), so tinyplot(1:10, array(1:10, c(1, 10)))
  works like plot().
- Forward `data` to sanitize_facet(), so two-sided facet formulas work
  with the default method. Previously `data` resolved to utils::data.

Closes #548
@grantmcdermott
grantmcdermott merged commit 7221667 into main Sep 27, 2026
3 checks passed
@grantmcdermott
grantmcdermott deleted the array-method branch September 27, 2026 03:10
grantmcdermott added a commit that referenced this pull request Sep 27, 2026
Clears the R CMD check NOTE about an undefined global function,
introduced with tinyplot.array() in #746.
grantmcdermott added a commit that referenced this pull request Sep 28, 2026
* chore: prepare v0.8.0 CRAN release

Bump version to 0.8.0, rename the NEWS development heading, and
update cran-comments.md for this release. The revdep section is a
placeholder until the revdep-v0.8.0 workflow finishes.

* docs: add v0.8.0 revdep results to cran-comments

* chore: exclude tests from CRAN tarball

* fix: namespace utils::type.convert in array_plot

Clears the R CMD check NOTE about an undefined global function,
introduced with tinyplot.array() in #746.

* submission note and revert rbuildignore
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.

Incompatible with arrays

1 participant