Closed r-drigo closed 1 year ago
Howdy! I modified/simplified your reprex, and I guessed icon_list
was:
icon_list <- c("circle", "check", "square", "arrow-up", "arrow-down")
But I am also not sure I am following completely. Are you looping to apply the function to each column?
You could simplify the call to:
test_tibble_gt |>
gt_fa_column(
contains("icon"),
palette = icons_pallete
)
Regardless, I've removed that check (palette unique length) for now as it's been finicky. Try the latest dev version here on GH.
library(gtExtras)
#> Loading required package: gt
library(dplyr)
icon_list <- c("circle", "check", "square", "arrow-up", "arrow-down")
set.seed(20230316)
test_tibble <- tibble::tibble(
col_1 = sample(1:5, 3),
icon_1 = sample(icon_list, 3, replace = TRUE),
col_2 = sample(1:5, 3),
icon_2 = sample(icon_list, 3, replace = TRUE),
col_3 = sample(1:5, 3),
icon_3 = sample(icon_list, 3, replace = TRUE),
col_4 = sample(1:5, 3),
icon_4 = sample(icon_list, 3, replace = TRUE),
col_5 = sample(1:5, 3),
icon_5 = sample(icon_list, 3, replace = TRUE),
col_6 = sample(1:5, 3),
icon_6 = sample(icon_list, 3, replace = TRUE)
)
icons_pallete <- c(
"circle" = "black",
"check" = "blue",
"square" = "red",
"arrow-up" = "gold",
"arrow-down" = "green"
)
test_tibble_gt <- test_tibble %>%
gt()
test_tibble_gt |>
gt_fa_column(
contains("icon"),
palette = icons_pallete
) |>
gt_reprex_image()
Created on 2023-03-16 by the reprex package (v2.0.1)
Hi
I have a table with multiple columns with strings to be turned into FontAwesome icons. The function
gt_fa_column
works just great for a single column. My code sets all columns inside a loop, one by one, selecting the proper number of colors to the palette. But in some cases it complains:"Error in FUN(X[[i]], ...) : The length of the unique elements must match the palette length".
I can't find a pattern for that. Usually, when I have 6 columns, the loop deals with all of them, and crashes in the 6th execution, even though I assure the palette length is correct.
The code below is similar to the one I'm using. I have no clue why it crashes only when I have 6 of such columns, so just in case that's what I mimic here. Please note how the first loop generates an error, and the second one does not, even though it is basically similar to the concept of
gt_fa_column
as far as I understand.