0

how can I exclude NA values from being transformed into an icon? With the code below you require to have NA-Icons aswell, which I just colored like the backround to disappear. Is there a better way to just exclude NA to be required to transform? All entries in my column is character-class.

text_transform(
    locations = cells_body(columns = 2:ncol(df)),
    fn = function(x) {
      # loop over the elements of the column
      map_chr(x, ~ local_image(
        filename = paste0(.x, ".png"),
        height = 13))}) %>%
Essi
  • 761
  • 3
  • 12
  • 22

1 Answers1

1

Here I abstracted away from the particulars, but show a method you can use to solve your own case.

library(purrr)
library(dplyr)

local_image <- function(f, h) {
  paste(f, h, sep = "_")
}

# spoil with an NA
x <- c(letters[1:3], NA)
# if else to dodge it from being in local_image
(step_1 <- map_chr(
  x,
  ~ if_else(!is.na(.x),
    local_image(
      f = paste0(.x, ".png"),
      h = 13
    ), NA
  )
))

# clear the NAs
(step_2 <- step_1[!is.na(step_1)])
Nir Graham
  • 2,567
  • 2
  • 6
  • 10