Created
March 26, 2024 22:50
-
-
Save JanMarvin/5d88fb595d41e2b1b9e75eca2587a114 to your computer and use it in GitHub Desktop.
dims around the worksheet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(openxlsx2) | |
packageVersion("openxlsx2") | |
# the dimensions go in here | |
dim_matrix <- matrix("", 20, 10) | |
# matrix of size 2 x 2 | |
mm <- matrix(1:4, 2, 2) | |
dim_matrix[1, 1] <- wb_dims(x = mm, col_names = FALSE) | |
# get the first row | |
for (col in seq_len(ncol(dim_matrix) - 1L)) { | |
dim_matrix[1, col + 1L] <- wb_dims(x = mm, from_dims = dim_matrix[1, col], | |
right = 2, col_names = FALSE) | |
} | |
# get the rest of the matrix | |
for (row in seq_len(nrow(dim_matrix) - 1L)) { | |
dim_matrix[row + 1L, ] <- vapply(dim_matrix[row, ], FUN = function(x) { | |
wb_dims(x = mm, from_dims = x, below = 2, col_names = FALSE) | |
} , NA_character_) | |
} | |
# prepare output | |
dims <- c(dim_matrix) | |
clrs <- rep(rainbow(n = ncol(dim_matrix)), each = nrow(dim_matrix)) | |
# create workbook and loop over the dims | |
wb <- wb_workbook()$add_worksheet(zoom = 40) | |
for (i in seq_along(dims)) { | |
wb$add_fill(dims = dims[i], color = wb_color(clrs[i])) | |
} | |
# show output | |
if (interactive()) wb$open() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment