Applying condformat rules for multiple columns

Viewed 360

I am using condformat package to color each column of a dataframe. I am able to do single column but don't know how to apply for all columns without using colnames (as they change dynamically)

I used the following code to achieve conditional column coloring for single column

data(iris)
library(condformat)
dat<-iris[c(1:5,70:75, 120:125),]
condformat(dat) %>%
  rule_fill_discrete(Sepal.Width,
                     expression = Sepal.Width > Petal.Length)

The above code changes the color of the column (sepal.width) successfully. But what I want is to apply the same condition for all columns (for example c(1:5) where without knowing the column names. I tried like . and x etc. but nothing helped. This applies for expression as well.

1 Answers

Right now it is not straightforward to do with condformat. Here is an example that should work on the iris dataset.

library(condformat)
cf <- condformat(iris)
columns <- c("Sepal.Width", "Sepal.Length")
for (col %in% rlang::syms(columns)) {
  cf <- cf %>% rule_fill_discrete(!!col, expression = !!col > 0.5)
}
cf

Disclaimer: I am author of this package.

Related