Skip to content
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

Be strict about cols, widths, hidden lengths. #991

Merged
merged 12 commits into from Apr 30, 2024
Merged

Be strict about cols, widths, hidden lengths. #991

merged 12 commits into from Apr 30, 2024

Conversation

olivroy
Copy link
Collaborator

@olivroy olivroy commented Apr 12, 2024

May want to change errors for warnings?

two things here

  1. hidden is documented as a vector of logical, but class is not enforced, and in tests, integers are provided?
  2. I tripped on the length difference of cols and widths

At some point, my script was like that

wb <- wb_workbook()
wb$add_worksheet()
wb$set_col_widths(widths = c(10, 15), cols = c(2, 3))

but then I realized that I needed a wider column 4 and I did this:

wb <- wb_workbook()
wb$add_worksheet()
wb$set_col_widths(widths = c(10, 15), cols = c(2, 3, 4))

or the opposite, but to realize very much later that it was the wrong thing.

Base R recycling rules are sometimes not what you expect

rep(c(1, 2 ), length.out = 3) # is successful,
#> 1, 2, 1

To avoid breaking changes, I could change this to warnings. I used %% to only error if one is not a multiple of the other,

Copy link
Owner

@JanMarvin JanMarvin left a comment

Choose a reason for hiding this comment

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

I agree that seems a bit sketchy. I prefer non breaking changes very much. Preferably they don’t interfere with me as user at all. If I was happy with the code a few months ago, why would I change my mind?

I will think about it over the weekend. Thanks for the PR and the explanations.

NEWS.md Outdated Show resolved Hide resolved
R/class-workbook.R Outdated Show resolved Hide resolved
R/class-workbook.R Outdated Show resolved Hide resolved
tests/testthat/test-class-workbook.R Show resolved Hide resolved
@olivroy
Copy link
Collaborator Author

olivroy commented Apr 12, 2024

No worries, this lacks polishing, but wanted to bake a PR before I forgot about this and / or get bitten again.

@JanMarvin
Copy link
Owner

We might have to adjust the changes to test order. It seems that at least one test is now flaking on CI

R/class-workbook.R Outdated Show resolved Hide resolved
@olivroy
Copy link
Collaborator Author

olivroy commented Apr 16, 2024

We might have to adjust the changes to test order. It seems that at least one test is now flaking on CI

Does adding testsetup() on top of test-readSources or test-cloneWorksheet work?

@JanMarvin
Copy link
Owner

Not sure, it’s just one test is starting to fail because a testfile is not yet available

@olivroy
Copy link
Collaborator Author

olivroy commented Apr 16, 2024

Maybe it is just gh API limitations then..

@olivroy olivroy mentioned this pull request Apr 16, 2024
@JanMarvin
Copy link
Owner

Hi @olivroy , sorry, me opening #1005 was a little late and I didn't want to rush you. I usually strive to announce new releases a bit earlier so that people (well, mostly me) can make time to finish PRs and do further cleanups.

Unfortunately this time I have received a CRAN notification to push a fix for the isBlankString() usage and I want to have a little buffer time in case there are other hickups with the submission. (May 1st is labor day in Germany and a national holiday, that's why I picked it.) Just let me know how far this PR is and if it needs additional development time so that we can make time for this.

@olivroy
Copy link
Collaborator Author

olivroy commented Apr 30, 2024

to me, it feels like it is finished. just adding warnings in the case of incompatible widths / hidden supplied to set_col_widths.

Leaving the rest unchanged and moving tests in a new entry to catch wb_set_col_widths

It feels less intrusive than throwing error, but signaling that the input may provide unexpected results

Copy link
Owner

@JanMarvin JanMarvin left a comment

Choose a reason for hiding this comment

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

Thanks, I just now realize that you have simply moved the expect_error() tests, but I actually feel that testing against some condition is worth it (we once had a expect_warning() test that succeeded, but the warning was produced for reasons unrelated to openxlsx2 and not what was supposed to be covered 😀

Otherwise good to go!

tests/testthat/test-class-workbook.R Outdated Show resolved Hide resolved
tests/testthat/test-class-workbook.R Outdated Show resolved Hide resolved
tests/testthat/test-class-workbook.R Outdated Show resolved Hide resolved
@olivroy
Copy link
Collaborator Author

olivroy commented Apr 30, 2024

Thanks! So, I guess you can merge and then test revdeps?

R/class-workbook.R Outdated Show resolved Hide resolved
@JanMarvin
Copy link
Owner

Please fix the lintr warning and the probably unintended change in the example code. Feel free to squash merge afterwards. Thanks!

@olivroy
Copy link
Collaborator Author

olivroy commented Apr 30, 2024

Fixed both the lintr warning and the typo.. Sometimes RStudio types things for me :(

@olivroy olivroy merged commit 45e3c32 into main Apr 30, 2024
9 checks passed
@olivroy olivroy deleted the set-col-widths branch April 30, 2024 16:25
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.

None yet

2 participants