Skip to content

Commit

Permalink
Merge pull request #39 from JulienBlasco/path-argument
Browse files Browse the repository at this point in the history
Evolution of the `path` argument
  • Loading branch information
ddotta authored Jun 11, 2024
2 parents 89511db + 34bbba1 commit 3d9074c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
5 changes: 3 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# 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
* (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)
* `path` can now be supplied as a file name with full path instead of a directory name (#29)

# tablexlsx 1.0.0

Expand Down
20 changes: 12 additions & 8 deletions R/toxlsx.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#' See examples gallery : <https://ddotta.github.io/tablexlsx/articles/aa-examples.html>
#'
#' @param object data.frame to be converted to excel
#' @param path path to save excel file (either a directory name or a file name with full path)
#' @param tosheet list of sheet names for each element of object.
#' If omitted, sheets are named by default "Sheet 1", "Sheet 2"...
#' @param title list of title for each element of object
Expand All @@ -23,8 +24,7 @@
#' @param mergecol list of character vectors that indicate the columns for which we want to merge the modalities
#' @param bygroup list of character vectors indicating the names of the columns by which to group
#' @param groupname list of booleans indicating whether the names of the grouping variables should be written
#' @param path path to save excel file
#' @param filename name for the excel file ("Export" by default)
#' @param filename name for the excel file ("Export" by default). Ignored if `path` is a file name.
#' @param asTable logical indicating if data should be written as an Excel Table (FALSE by default)
#' @param automaticopen logical indicating if excel file should open automatically (FALSE by default)
#'
Expand All @@ -40,6 +40,7 @@
#' @export
#'
toxlsx <- function(object,
path,
tosheet = list(),
title = list(),
columnstyle = list("default" = NULL),
Expand All @@ -49,7 +50,6 @@ toxlsx <- function(object,
mergecol = NULL,
bygroup = list(),
groupname = FALSE,
path,
filename = "Export",
asTable = FALSE,
automaticopen = FALSE) {
Expand Down Expand Up @@ -254,18 +254,22 @@ toxlsx <- function(object,

}

if (dir.exists(path)) {
full_path <- file.path(path, paste0(filename,".xlsx"))
} else {
full_path <- path
if (filename != "Export") warning("The supplied filename was overriden by the supplied path.")
}

# Save workbook
openxlsx::saveWorkbook(
wb,
file.path(
path,
paste0(filename,".xlsx")
),
full_path,
overwrite = TRUE
)

Sys.sleep(0.01)
cli_alert_success("\nYour Excel file '{filename}.xlsx' is available in the folder '{path}'")
cli_alert_success("\nYour Excel file '{basename(full_path)}' is available in the folder '{dirname(full_path)}'")

# Open workbook automatically if automaticopen is TRUE
if (isTRUE(automaticopen)) {
Expand Down
8 changes: 4 additions & 4 deletions man/toxlsx.Rd

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

0 comments on commit 3d9074c

Please sign in to comment.