if (FALSE) {
# Create a simple matrix
mat <- matrix(1:6, nrow = 3, ncol = 2,
dimnames = list(c("r1", "r2", "r3"),
c("c1", "c2")))
# Create a matsindf data frame
df <- tibble::tibble(mat = list(mat, mat+1, mat+2),
worksheet_name = c("A", "B", "C"))
# Create a temporary file
mat_temp_path <- tempfile(pattern = "write_mat_to_excel_test_file",
fileext = ".xlsx")
# Write the file.
df |>
write_mats_to_excel(mat_colname = "mat",
worksheet_names = "worksheet_name",
path = mat_temp_path,
overwrite_file = TRUE)
# Check the appearance
openxlsx2::wb_open(mat_wb)
if (file.exists(mat_temp_path)) {
res <- file.remove(mat_temp_path)
}
}
Run the code above in your browser using DataLab