Create an Excel workbook with worksheets
Value
TRUE if the Excel file was successfully created.
FALSE, with a warning, if the file already exists and
replace is FALSE. Other problems are signaled as errors
rather than returned as FALSE; examples are a number of
sheetnames that differs from the length of df_list, a folder
for file that does not exist and an invalid worksheet name.
Examples
library(nprcgenekeepr)
make_df_list <- function(size) {
df_list <- list(size)
if (size <= 0) {
return(df_list)
}
for (i in seq_len(size)) {
n <- sample(2:10, 2, replace = TRUE)
df <- data.frame(matrix(data = rnorm(n[1] * n[2]), ncol = n[1]))
df_list[[i]] <- df
}
names(df_list) <- paste0("A", seq_len(size))
df_list
}
df_list <- make_df_list(3)
sheetnames <- names(df_list)
wkbkFile <- file.path(tempdir(), "example_excel_wkbk.xlsx")
create_wkbk(
file = wkbkFile,
df_list = df_list,
sheetnames = sheetnames,
replace = FALSE
)
#> [1] TRUE
if (file.exists(wkbkFile)) {
file.remove(wkbkFile)
}
#> [1] TRUE
