-
Notifications
You must be signed in to change notification settings - Fork 85
Fix to align()
's default align
argument
#623
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Removes `context()` as this is encapsulated by the test file name. Swaps `expect_equivalent()` with `expect_equal(ignore_attr = TRUE)`
…cepts multiple values.
Thanks David, I see you have applied some of the fixes in 85e6227.
I'd like to reassure you that the changes in my pull request continue to allow the There is one part of my pull request that you did not copy over to 85e6227 that I should highlight the importance of. This was the transition from using if (length(align_value) == length(j)) { to if (length(j) %% length(align_value) == 0) { This was to address the second example in my original reprex, where the length of ft <- flextable(head(mtcars[, 2:9]))
align_vals <- c("left", "right")
ft <- align(ft, align = align_vals, part = "all") Provides no error or warning but yields this result. The behaviour is understandable under the R framework: this is just an example value recycling between different length vectors. But this leaves you with a design decision where you should pick one of:
I'm sorry for the size of the ab81bcc commit. Most of this was collateral to move to testthat version 3, which allows for snapshots to ensure the correct alignment appeared in the cells, but it appears you have a much neater and more compact strategy that uses an The collection of tests added to tests/testthat/test-styles.R seem long but was beneficial to verify the expected behaviour in a variety of scenarios a user might throw at it. If you decide to take option 1 (allow recycling of |
- written by @keithnewman See #623
sorry, I misread your solution. And thanks, it's now integrated. |
and use `usethis::use_tidy_description()` See #623
I encountered an issue with the
align()
method when not setting analign
argument and relying on the default value for thealign
argument. Usage from thealign()
docs:However, a few lines later, the
match.arg
applied toalign
hasseveral.ok = TRUE
, which means all four values are accepted as thealign
argument.This becomes a problem when the number of columns is not a multiple of 4 as the align argument tries to recycle itself across columns. Newer versions of R will error when recycling over a non-multiple value. The example in the documentation didn't flag this because it is an example dataset with 4 columns.
A small example to highlight the issue is:
Created on 2024-04-11 with reprex v2.1.0
These changes to
align()
attempt to patch this and reinforce the testing of thealign()
method. For the testing, I've employed test snapshots to confirm the relevant styling does filter down correctly into the table. However this requires a move to testthat version 3. The overhead of transitioning code to testthat 3 makes this PR cluttered, so you may find it easier to review one commit at a time. The three commits arealign()
usethis::use_tidy_description()
(not required, but an easy win)More details about the changes made, reasons why, and consequences are in the NEWS.md file.