8
8
# ' See examples gallery : <https://ddotta.github.io/tablexlsx/articles/aa-examples.html>
9
9
# '
10
10
# ' @param object data.frame to be converted to excel
11
+ # ' @param path path to save excel file (either a directory name or a file name with full path)
11
12
# ' @param tosheet list of sheet names for each element of object.
12
13
# ' If omitted, sheets are named by default "Sheet 1", "Sheet 2"...
13
14
# ' @param title list of title for each element of object
23
24
# ' @param mergecol list of character vectors that indicate the columns for which we want to merge the modalities
24
25
# ' @param bygroup list of character vectors indicating the names of the columns by which to group
25
26
# ' @param groupname list of booleans indicating whether the names of the grouping variables should be written
26
- # ' @param path path to save excel file
27
- # ' @param filename name for the excel file ("Export" by default)
27
+ # ' @param filename name for the excel file ("Export" by default). Ignored if `path` is a file name.
28
28
# ' @param asTable logical indicating if data should be written as an Excel Table (FALSE by default)
29
29
# ' @param automaticopen logical indicating if excel file should open automatically (FALSE by default)
30
30
# '
40
40
# ' @export
41
41
# '
42
42
toxlsx <- function (object ,
43
+ path ,
43
44
tosheet = list (),
44
45
title = list (),
45
46
columnstyle = list (" default" = NULL ),
@@ -49,7 +50,6 @@ toxlsx <- function(object,
49
50
mergecol = NULL ,
50
51
bygroup = list (),
51
52
groupname = FALSE ,
52
- path ,
53
53
filename = " Export" ,
54
54
asTable = FALSE ,
55
55
automaticopen = FALSE ) {
@@ -254,18 +254,22 @@ toxlsx <- function(object,
254
254
255
255
}
256
256
257
+ if (dir.exists(path )) {
258
+ full_path <- file.path(path , paste0(filename ," .xlsx" ))
259
+ } else {
260
+ full_path <- path
261
+ if (filename != " Export" ) warning(" The supplied filename was overriden by the supplied path." )
262
+ }
263
+
257
264
# Save workbook
258
265
openxlsx :: saveWorkbook(
259
266
wb ,
260
- file.path(
261
- path ,
262
- paste0(filename ," .xlsx" )
263
- ),
267
+ full_path ,
264
268
overwrite = TRUE
265
269
)
266
270
267
271
Sys.sleep(0.01 )
268
- cli_alert_success(" \n Your Excel file '{filename}.xlsx ' is available in the folder '{path }'" )
272
+ cli_alert_success(" \n Your Excel file '{basename(full_path)} ' is available in the folder '{dirname(full_path) }'" )
269
273
270
274
# Open workbook automatically if automaticopen is TRUE
271
275
if (isTRUE(automaticopen )) {
0 commit comments