0

I'm having an error when apply conditional formatting. I want to color red or highlight red the values in the last column that are higher than the column before. It's not a fixed column since I add a new column each time I run the code.

library(readxl)
library(openxlsx)


file <- read_excel("path", col_names = TRUE)
posStyle <- createStyle(fontColour = rgb(1,0,0))
conditionalFormatting(file, cols = file[,ncol(file)], rows = 2:85, file[,ncol(file)]>file[,ncol(file) -1], 
                      style =  posStyle)

When i'm running it I get this error: Error in Encoding(v) : a character vector argument expected

Activity Count State Count 2 Count 3
xx Pending 2 1 4
xx Pending 2 3 2

I want for example the number 2 on count 3 to be red since is less than number 3 on count 2.

WHat does it means in this case?

  • It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick Apr 28 '21 at 19:41
  • Please share a dput() of your data so we can see how the data is stored (see examples in the link I provided). Explicitly list any non-base R packages you are using. It’s not clear where these functions are coming from. – MrFlick Apr 28 '21 at 20:32
  • Putting wrong values for openxlsx options through `options()` gave me such a cryptic error message – Samuel Allain Apr 28 '22 at 16:42

0 Answers0