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

Writexlsx params #194

Merged
merged 22 commits into from
Jun 1, 2021
Merged

Writexlsx params #194

merged 22 commits into from
Jun 1, 2021

Conversation

jmbarbone
Copy link
Contributor

Resolves #192 and #187.

Adds the buildWorkbook() function to extract the relevant processes from write.xlsx(). The method in which I used should also allow for all applicable parameters passed through ... into the other function calls.

I have also made some formatting changes and small improvements in some of the code I was looking at. A large portion is simplifying the use of grep() and grepl() and adding some assert_*() functions which should make parameter checking easier and reduce some of the duplicate code.

It may be worth while, too, to update some of the tests that use write.xlsx(x, file); wb <- read.xlsx(file) as buildWorkbook() now accomplishes that.

* when rownames is TRUE the first column (which already has * a name made) is removed
this makes sure that the made names start with X1, X2 rather than X2, X3
* simplifies x[grepl()] to grep(value = TRUE) when appropriate
* uses inherits() or is.*() for class checking
* formatting
speed is virtually the sample but grep(value = TRUE) less memory allocation than x[grepl()]
@codecov-commenter
Copy link

codecov-commenter commented May 29, 2021

Codecov Report

Merging #194 (9fda214) into master (42d5e63) will decrease coverage by 0.48%.
The diff coverage is 88.10%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #194      +/-   ##
==========================================
- Coverage   65.10%   64.62%   -0.49%     
==========================================
  Files          32       34       +2     
  Lines        9105     8873     -232     
==========================================
- Hits         5928     5734     -194     
+ Misses       3177     3139      -38     
Impacted Files Coverage Δ
R/openxlsx.R 60.00% <ø> (ø)
R/workbook_column_widths.R 20.58% <0.00%> (-27.46%) ⬇️
R/wrappers.R 50.99% <ø> (+0.13%) ⬆️
R/asserts.R 65.71% <65.71%> (ø)
R/writeData.R 87.15% <80.55%> (+2.09%) ⬆️
R/writeDataTable.R 84.61% <81.81%> (+10.35%) ⬆️
R/readWorkbook.R 87.68% <93.06%> (+0.97%) ⬆️
R/utils.R 94.11% <93.75%> (+34.11%) ⬆️
R/WorkbookClass.R 57.16% <94.73%> (-0.19%) ⬇️
R/loadWorkbook.R 83.59% <94.82%> (+0.26%) ⬆️
... and 10 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 42d5e63...9fda214. Read the comment docs.

Copy link
Collaborator

@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.

Coding looks nice and I like the wrappers for some of the functions, but I'm not gonna review a 3.5k diff of whitespace changes 😄

@@ -69,43 +69,47 @@
#' }
Copy link
Collaborator

Choose a reason for hiding this comment

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

why did you modify this file?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Mostly from adding assert_*()s and while testing for any differences in changing up write.xlsx() as there were a lot of testing code that used the write.xlsx(x, file); read.xlsx(file) process

@@ -29,40 +29,40 @@
#' category = "something"
Copy link
Collaborator

Choose a reason for hiding this comment

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

same for this file. only whitespace changes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Some changes at 386. Not entirely sure what all the white space changes are. I'm using Rstudio 1.4.1103, could there be some line return formatting causing this?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Rstudio has some formating options, removing trailing whitespace options, ensure empty line at the end of the file. For personal projects I usually stick with them, but all this unrelated noise make this pull request harder to read.
I'm not against the changes and from a quick glance they seem to improve the code, I just don't want to review all the lines of unrelated changes looking for possible issues in the new and changed code 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Rstudio has some formating options, removing trailing whitespace options, ensure empty line at the end of the file. For personal projects I usually stick with them, but all this unrelated noise make this pull request harder to read.

Agreed. I feel like this isn't going to be an isolated thing. Temping now to make one big PR of just white-noise?

Copy link
Collaborator

Choose a reason for hiding this comment

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

First of, that's not my call to make (poking @ycphs) and ideally it would be a decision unrelated to an IDE configuration.
Personally, I would prefer to introduce such changes only when applying code changes. Iirc correctly, such whitespace related bulk commits make git bisecting and blaming harder, but I didn't check that.
Finally, I think that this should not be a blocker for this pull request, but I won't volunteer right now to review it. (And I know projects, where such pull request would be closed without any hesitation.)

Copy link
Owner

Choose a reason for hiding this comment

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

I totally agree with @JanMarvin. It is hard to read, but I will merge the PR. The next time it would be great if only the rows with actual changes is pushed.

R/writeData.R Outdated
@@ -14,6 +14,7 @@
#' \code{c(startCol, startRow)}.
#' @param colNames If \code{TRUE}, column names of x are written.
#' @param rowNames If \code{TRUE}, data.frame row names of x are written.
#' @param row.names Deprecated, please use \code{rowNames} instead
Copy link
Collaborator

Choose a reason for hiding this comment

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

I do not get this. This looks as if you added and deprecated it in the very same moment?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

row.names had been originally passed from write.xlsx() and converted to rowNames before writeData() and writeDataTable(). This was also done with col.names and colNames but I missed that because the latter wasn't used in testing.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I understand. I initially was wondering, why you'd deprecate functions from a stable API, but using similar arguments looks like an improvement. 👍

@@ -12,6 +12,7 @@
#' A vector of the form c(startCol, startRow)
#' @param colNames If \code{TRUE}, column names of x are written.
#' @param rowNames If \code{TRUE}, row names of x are written.
#' @param row.names Deprecated, please use \code{rowNames} instead
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same for this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As above.

@@ -383,91 +383,95 @@ addWorksheet <- function(
od <- getOption("OutDec")
options("OutDec" = ".")
on.exit(expr = options("OutDec" = od), add = TRUE)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@JanMarvin some changes here

jmbarbone added 2 commits May 30, 2021 11:09
buildWorkbook() is intended to be used with an assignment operator, so an explicit return should reinforce this
adds warning and tests for use of col.names
@ycphs ycphs merged commit 3fae773 into ycphs:master Jun 1, 2021
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.

New feature: buildWorkbook()
4 participants