Skip to content

Return columns normalize(), ranktransform(), and center() can't handle unchanged - #754

Merged
jmgirard merged 4 commits into
mainfrom
hotfix-transformers-date
Nov 26, 2026
Merged

jmgirard merged 4 commits into
mainfrom
hotfix-transformers-date

Conversation

@jmgirard

Copy link
Copy Markdown
Contributor

normalize() and ranktransform() failed with "no applicable method" on a data frame with a column of a class that has no method, such as Date, POSIXct, or haven_labelled. center() failed on the same data frames, because center.data.frame() reads the center attribute of every selected column, and a skipped column has none:

d <- data.frame(x = c(1:9, 100), date = .Date(18262 + 0:9))
normalize(d)
#> Error in UseMethod("normalize"): no applicable method for 'normalize' applied to an object of class "Date"
center(d)
#> Error in vapply(x[my_args$select], function(z) attributes(z)$center, numeric(1)):
#>   values must be length 1, but FUN(X[[2]]) result is length 0

This adds normalize.default() and ranktransform.default(), which return the column unchanged with a message, like rescale.default(). center() now reads the attributes only from the columns it centered. The data frame methods of ranktransform() now pass verbose on, so verbose = FALSE silences the new message.

@jmgirard
jmgirard requested a lite review from Copilot November 26, 2026 01:07

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

4 open issues
What changed in this PR

Fixes normalize(), ranktransform(), and center() failures on data frames that include columns whose classes aren’t transformable (e.g., Date), ensuring such columns remain unchanged and don’t break attribute handling.

Changes:

  • Add normalize.default() and ranktransform.default() to return unsupported classes unchanged (optionally emitting a message).
  • Propagate verbose through ranktransform.data.frame() / ranktransform.grouped_df() to silence the new message when requested.
  • Update center.data.frame() to only read center/scale attributes from columns that were actually centered; add regression tests.
File Description
tests/​testthat/​test-ranktransform.R Adds regression coverage for data frames containing a Date column.
tests/​testthat/​test-normalize.R Adds regression coverage for normalize() on data frames containing a Date column.
tests/​testthat/​test-center.R Adds regression coverage for center() on data frames containing a Date column.
R/​ranktransform.R Adds ranktransform.default() and passes verbose through data frame/grouped methods.
R/​normalize.R Adds normalize.default() to avoid errors on unsupported classes.
R/​center.R Fixes attribute extraction to only consider columns that were actually centered.
NEWS.md Documents the bug fix and new behavior (unchanged columns + message).
NAMESPACE Registers new S3 default methods for normalize() and ranktransform().

Review effort: Lite

Comment thread R/normalize.R Resolved
Comment thread R/ranktransform.R Resolved
Comment thread R/ranktransform.R Resolved
Comment thread R/center.R Resolved
@jmgirard

Copy link
Copy Markdown
Contributor Author

Copilot's review says insight::format_alert() only returns the text, so no message would show. It does call message(), and the tests now check that the message appears and that verbose = FALSE silences it.

@jmgirard
jmgirard merged commit 081a0ab into main Nov 26, 2026
23 of 26 checks passed
@jmgirard
jmgirard deleted the hotfix-transformers-date branch November 26, 2026 15:00
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.

3 participants