There are several reasons that it may be helpful to extract color information from an excel sheet using R. In my case, I was looking to exclude rows shaded red from analysis. Here are some other reasons it may be helpful:
In this example, I am looking for cells shaded Red (FFFF0000) in column F.
library(tidyxl)
formats <- xlsx_formats(path)
my_colors <- my_data$local$fill$patternFill$fgColor$rgb
data_file <- readxl::read_excel(path)
x <- xlsx_cells(path)
##FFFF0000 - Red
x %>%
filter(local_format_id %in%
which(formats$local$fill$patternFill$fgColor$rgb == "FFFF0000")) %>%
select(address, data_type) ->
location
red_cells <- data.table(location)
red_cells$col <- substr(red_cells$address,1,1)
red_cells$row <- as.numeric(gsub("[^0-9]+", "", red_cells$address))
red_cells <- subset(red_cells, col == 'F')
## Add one to row to account for column header
red_cells$row <- red_cells$row - 1