Skip to content

Fix str() spacing for units with R >= 4.7 - #450

Merged
Enchufa2 merged 1 commit into
mainfrom
fix-str-devel
Nov 13, 2026
Merged

Enchufa2 merged 1 commit into
mainfrom
fix-str-devel

Conversation

@Enchufa2

Copy link
Copy Markdown
Member

Fixes the str works test failure on R-devel (ubuntu-latest devel):

-    Units: [m/s] num [1:3] 1 0.5 0.333
+    Units: [m/s]num [1:3] 1 0.5 0.333

Cause

R-devel changed the spacing of str() output (NEWS: "str()'s output puts a space after "<some>:" … consistently now … by no longer prepending spaces, such that e.g. str(pi)'s output no longer starts with a space"). str.units() printed " Units: [m/s]" and relied on str() of the bare values to supply the separating space.

Fix

str.units() takes the leading space from str() of the bare values (via capture.output()), so it follows whichever convention the running R uses, rather than hard-coding the R version where it changed:

R 4.6.2 (unchanged) R-devel
top level Units: [m/s] num [1:3] 1 0.5 0.333 Units: [m/s] num [1:3] 1 0.5 0.333
in a list / data frame $ x: Units: [m/s] num ... $ x: Units: [m/s] num ...

The snapshot encoded one convention, so it is replaced by a test comparing str() of a units vector, and of a data frame holding one, against str() of the bare values. Unlike the snapshot, it also runs on CRAN.

Testing

  • R 4.6.2: full suite passes (730 tests, 0 failures).
  • R-devel r90825 (rocker/r-devel): full suite passes (718 tests, 0 failures; skips are optional packages not installed there).

🤖 Generated with Claude Code

R-devel's str() no longer prepends a space to an object's output; callers
now add it after "<name>:" instead. str.units() printed " Units: [m/s]"
and relied on str() of the bare values for the separating space, so it
printed "[m/s]num" there.

Take the leading space from str() of the bare values, so the output
follows whichever convention the running R uses, at top level and when
nested in lists and data frames. Replace the snapshot, which encoded one
convention, with a comparison against str() of the bare values.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Nov 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.95%. Comparing base (a823fef) to head (6974046).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #450      +/-   ##
==========================================
+ Coverage   92.93%   92.95%   +0.02%     
==========================================
  Files          21       21              
  Lines        1203     1207       +4     
==========================================
+ Hits         1118     1122       +4     
  Misses         85       85              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Enchufa2
Enchufa2 merged commit ecbaa91 into main Nov 13, 2026
38 of 39 checks passed
@Enchufa2
Enchufa2 deleted the fix-str-devel branch November 13, 2026 12:09
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