Skip to content

Commit

Permalink
Merge pull request #38 from JulienBlasco/fix-20-mergecol-exist-not
Browse files Browse the repository at this point in the history
Fix 20 : merge cols don't exist
  • Loading branch information
ddotta authored Jun 7, 2024
2 parents 47832f3 + 4c62f93 commit 89511db
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# tablexlsx (WIP)

* (fix) `toxlsx()` no longer fails when the `object` argument is the result of a computation #18
* provide meaningful error message if merge cols don't exist #20

# tablexlsx 1.0.0

This release includes :


* `add_table()` and `toxlsx()` now accept a `bygroup` argument that splits the table into groups before writing to the sheet #23
* most arguments to `add_table()` and `toxlsx()` can now be passed as atomic vectors. If the first argument is a single `data.frame`, the behavior is the same as for a lenght-one list. If the first argument is a list of `data.frame`s, those arguments are recycled in order to match the length of the list. This change applies to the arguments `tosheet`, `title`, `footnoteX`, `mergecol`, `bygroup`, `groupname` #19
* when a list is passed to `toxlsx()`, the `mergecol` argument can now be specified for each data.frame of the list #21
Expand Down
8 changes: 6 additions & 2 deletions R/add_table.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ add_table <- function(
TableFootnote1 = "",
TableFootnote2 = "",
TableFootnote3 = "",
MergeCol = NULL,
MergeCol = character(0),
ByGroup = character(0),
GroupName = FALSE,
asTable = FALSE) {
Expand All @@ -55,6 +55,10 @@ add_table <- function(
stop("asTable cannot be TRUE if ByGroup is defined")
}

if (!all(MergeCol %in% colnames(Table))) {
stop("All elements of MergeCol must be existing column names of Table")
}

# If the sheet does not exist in the Excel file, we create it; otherwise, we invoke it
if (!(SheetTitle %in% names(WbTitle))) {
mysheet <- openxlsx::addWorksheet(WbTitle, SheetTitle)
Expand Down Expand Up @@ -173,7 +177,7 @@ add_table <- function(
)

# If mergecol is filled in
if(!is.null(MergeCol)) {
if(length(MergeCol)>0) {

# loop on each column of mergecol
for (mycol in MergeCol) {
Expand Down
2 changes: 1 addition & 1 deletion man/add_table.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 89511db

Please sign in to comment.