highlight_cells: Highlight Cells

Description Usage Arguments Value Examples

View source: R/highlight_cells.R

Description

A lightweight cell highlighter that uses non-standard evaluation. This function is designed for interactive use. It's behavior outside of this context is not gaurenteed. For finer contral use an ifelse with paste within a ?dplyr::mutate statement.

Usage

1
2
3
4
5
6
7
8
highlight_cells(
  data,
  rows,
  columns = seq_len(ncol(data)),
  left = "<b>",
  right = gsub("(<)([^> ]+)([^>]*>)", "\\1/\\2>", left),
  ...
)

Arguments

data

A data.frame.

rows

An expression that evaluates to logical and is equal in length to the number of rows.

columns

A vector of either integer positions or character names corresponding to columns that should be highlighted. Defaults to all columns.

left

A highlighting tag for the left side of the cell value.

right

A highlighting tag for the right side of the cell value. Attempts to use the left input to create a corresponding right HTML based tag.

...

ignored.

Value

Returns a data.frame with the chosen cell values wrapped in highlight tags.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
highlight_cells(mtcars, rows = hp > 230 | qsec > 20)
highlight_cells(mtcars, rows = hp > 230, columns = 'hp')

## Not run: 
library(dplyr); library(tibble); library(pander)

mtcars %>%
    highlight_cells(rows = hp > 230, columns = 'hp') %>%
    highlight_cells(rows = qsec > 20, columns = 'qsec', left = '<b style="color:blue;">')  %>%
    rownames_to_column('car') %>%
    data.frame(stringsAsFactors = FALSE, check.names = FALSE) %>%
    pander::pander(split.tables = Inf, justify = alignment(.))

## End(Not run)

## Not run: 
if (!require("pacman")) install.packages("pacman")
pacman::p_load(tidyverse, magrittr)

set.seed(10)
data_frame(
    w = paste(constant_months, rep(2016:2017, each = 12))[1:20] ,
    x = rnorm(20, 200000, 75000)
) %>%
    {
        a <- .
        rbind(
            a,
            a %>%
                mutate(w = 'Total') %>%
                group_by(w) %>%
                summarize(x = sum(x))
        )
    } %>%
    mutate(
        y = f_denom(x, prefix = '$'),
        z = f_denom(x, mix.denom = TRUE, prefix = '$'),
        x = f_comma(f_dollar(x, 2))
    )  %>%
    highlight_cells(w == 'Total') %>%
    data.frame(stringsAsFactors = FALSE, check.names = FALSE) %>%
    pander::pander(split.tables = Inf, justify = alignment(.))

## End(Not run)

numform documentation built on Oct. 10, 2021, 1:10 a.m.