create_wkbk: Creates an Excel workbook with worksheets.

Description Usage Arguments Value Examples

View source: R/create_wkbk.R

Description

Creates an Excel workbook with worksheets.

Usage

1
create_wkbk(file, df_list, sheetnames, replace = FALSE)

Arguments

file

filename of workbook to be created

df_list

list of data frames to be added as worksheets to workbook

sheetnames

character vector of worksheet names

replace

Specifies if the file should be replaced if it already exist (default is FALSE).

Value

TRUE if the Excel file was successfully created. FALSE if any errors occurred.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
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)
create_wkbk(file = file.path(tempdir(), "example_excel_wkbk.xlsx"),
            df_list = df_list,
            sheetnames = sheetnames, replace = FALSE)

rmsharp/nprcmanager documentation built on April 24, 2021, 3:13 p.m.