Skip to content

fixed error in def_colwidths() when a column label is too long#384

Draft
eanokian wants to merge 11 commits into
devfrom
281_error_def_colwidths
Draft

fixed error in def_colwidths() when a column label is too long#384
eanokian wants to merge 11 commits into
devfrom
281_error_def_colwidths

Conversation

@eanokian

@eanokian eanokian commented Jun 11, 2026

Copy link
Copy Markdown
Collaborator

Pull Request

Fixes #281

Checks

  • (Have you updated the NEWS.md ?)
  • (Have you added proper tests for new functions/features ?)
  • (Have you added new functions to the pkgdown.yml ?)
  • (Have you run document() on new functions ?)

Comment thread R/colwidths.R Outdated
@eanokian eanokian self-assigned this Jun 12, 2026
@eanokian
eanokian marked this pull request as ready for review June 12, 2026 10:35
@eanokian
eanokian requested a review from gmbecker June 12, 2026 10:35
Comment thread R/colwidths.R
break
}
newrow <- possdfii[ii, ]
newrow <- possdfii[ii, ] # TODO: this line seems odd,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

correct, this line is just completely wrong.

The correct is something like either
newrow <- possdfii[which.max(possdfii$colwidth), ]

or

newrow <- possdfii[which.min(possdfii$colwidth), ]

depending on whether we want to choose the most conservative (max) or most agressive (min) packing. I think aggressive is right because that leaves the most room to successfully pack other columns.

More accurately I think what we want is the narrowest column width that takes up exactly one line less than the the column label did previously, so in addition to the above, the previous

possdfii <- possdf[possdf$col_num == colii & possdf$lbl_lines < old_lbl_lns, ]

would need to change to

possdfii <- possdf[possdf$col_num == colii & possdf$lbl_lines == old_lbl_lns - 1, ]

I think the code after those changes would be safe but an escape hatch that immediately bails if old_lbl_lns is already 1 wouldn't hurt anything

Comment thread R/colwidths.R
} else {
msg <- paste("Unable to reduce label rows required.")
}
message(msg)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

yeah I noticed this too, crazy

Comment thread R/colwidths.R
while (!done) {
oldwdths <- curdf$colwidth
curdf <- constrict_lbl_lns(curdf, possdf, verbose = verbose)
curdf <- constrict_lbl_lns(curdf, possdf, avail_spc = spcleft, verbose = verbose)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

👍

Comment thread R/colwidths.R
oldwdths <- curdf$colwidth
curdf <- constrict_lbl_lns(curdf, possdf, verbose = verbose)
curdf <- constrict_lbl_lns(curdf, possdf, avail_spc = spcleft, verbose = verbose)
if (all.equal(curdf$colwidth, oldwdths)) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

this needs to be isTRUE(all.equal(curdf$colwidth, oldwidths))

Only reason the code ever worked is that this code was either never reached at all or never reached when it was false, likely the former.

@gmbecker gmbecker left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

There are enough changes to code here (and turning on code paths that were turned off by bugs) that I think we need to look at what is coming out and make sure its still sane. @jkovach2 @eanokian

@eanokian
eanokian marked this pull request as draft June 25, 2026 12:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants