title: Coloring rows with kableExtra based on cell values
body: <p>I use R markdown in combination with LaTeX to create PDF reports. To generate tables I use the kableExtra package.</p>
  <p>I'd like to change the styling of rows based on the values in a particular column. I've been trying cell_spec, but as far as I can see it only changes the styling of the value in the column and not the entire row.</p>
  <p>For example, in the table below I'd like to highlight all cars with more than six cylinders. So the result should look like:</p>
  <pre><code>library(knitr)
  library(kableExtra)
  library(tidyverse)
  
  mtcars |&gt; 
    slice(1:5) |&gt; 
    select(mpg:wt) |&gt;
    kable(booktabs = T) %&gt;%
    kable_styling() %&gt;%
    row_spec(5, bold = T, color = &quot;white&quot;, background = &quot;red&quot;)
  </code></pre>
  <p><a href="https://i.stack.imgur.com/5NDWa.png" rel="noreferrer"><img src="https://i.stack.imgur.com/5NDWa.png" alt="enter image description here" /></a></p>
  <p>But here I specified a row number, which I don't want to do. It should be decided automatically based on the number of cylinders. Using cell_spec, I'm able to get the following:</p>
  <pre><code>mtcars |&gt; 
    slice(1:5) |&gt; 
    select(mpg:wt) |&gt;
    rownames_to_column('cars') %&gt;% # used to store row names (mutate deletes them)
    mutate(
    cyl = cell_spec(cyl, color = ifelse(cyl &gt; 6, &quot;white&quot;, &quot;black&quot;),
                    background = ifelse(cyl &gt; 6, &quot;red&quot;, &quot;white&quot;),
                    bold = ifelse(cyl &gt; 6, T, F))) %&gt;%
    column_to_rownames('cars') %&gt;% # used to put row names back in place
    kable(escape = F, booktabs = T) %&gt;%
    kable_styling()
  </code></pre>
  <p><a href="https://i.stack.imgur.com/xVt3G.png" rel="noreferrer"><img src="https://i.stack.imgur.com/xVt3G.png" alt="enter image description here" /></a></p>
  <p>But this changes only the value in the cylinder column, and not the rest of the row.</p>
  <p>Is there a solution to my problem (preferrably without specifying the condition for every styling option)?</p>
  <p>EDIT:
  This is a different question than <a href="https://stackoverflow.com/questions/50665721/kableextra-conditionally-formatting-specific-rows-on-a-column">this one</a>, where someone wants to format a column based on values in that column, but wishes to exclude certain rows/entries. I don't want to exclude any rows, but I want the formatting to apply to the entire row (still conditioning on values in a particular column).</p>