Save Excel File
save_excel.RdSaves a data frame or a named list of data frames to an Excel file. If the file already exists, it will be overwritten.
Arguments
- x
A data frame or a named list of data frames to be saved.
- file_path
A character string specifying the path where the Excel file will be saved.
- sheet
Optional. A character string specifying the name of the sheet to save. If
NULL, all sheets (all elements of the list or the data frame itself) will be saved.
Details
If x is a data frame, it will be saved as a single sheet. If x is a named list of data frames, each element will be saved as a separate sheet unless the sheet parameter is specified, in which case only the specified sheet will be saved.
The function will create the directory specified in file_path if it does not exist.
Examples
df <- data.frame(a = 1:3, b = letters[1:3])
save_excel(df, "my_data.xlsx")
sheets <- list(sheet1 = data.frame(x = 1:2), sheet2 = data.frame(y = 3:4))
save_excel(sheets, "my_workbook.xlsx")
save_excel(sheets, "my_sheet.xlsx", sheet = "sheet1")