table_id_inject: Table hash addition for markup

Description Usage Arguments Details Examples

View source: R/table_inject.r

Description

A helper function to include a hashtag id code within a summary table. The summary table most commonly will take the form of a data frame object. For example, a descriptive summary table coming from the summarise function from the dplyr package. Can also specify a count table using the table function.

Usage

1
table_id_inject(table, id, conditions, variable = NULL, num_digits = NULL)

Arguments

table

A summary table object, most commonly will be a data.frame, but can also be a count table using the table function.

id

A vector of css id(s) to include

conditions

A character vector of conditions to include id. Must be same length as id. See details and examples for more information on how to specify the conditions.

variable

An optional list of column names to specify search of conditions. More than one variable can be specified in each element of the list. The list must be the same length as the conditions or id arguments.

num_digits

A numeric value to specify the number of decimal values to include in the final output.

Details

The conditions argument takes the following operators for numeric variables: >, >=, <, <=, ==. For character variables, only == can be used to specify the text string to match on. Care needs to be made to wrap ensure the text string is wrapped in quotations. See the examples for more details on this.

This function can also be part of a chain using the %>% operator from magrittr. See the examples for more details.

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
library(dplyr)
library(highlightHTML)

mtcars %>% 
  group_by(cyl) %>% 
  summarise(avg_mpg = mean(mpg), sd_mpg = sd(mpg)) %>%
  data.frame() %>% 
  table_id_inject(id = c('#bgred', '#bgblue', '#bggreen'), 
     conditions = c('< 2', '> 16', '== 15.1'))
  

mtcars %>% 
  group_by(cyl) %>% 
  summarise(avg_mpg = mean(mpg), sd_mpg = sd(mpg)) %>%
  data.frame() %>%
  table_id_inject(id = c('#bgred', '#bgblue'),
     conditions = c('<= 2', '< 16'), 
     variable = list(c('sd_mpg'), c('avg_mpg')))  
  
# text example
storms %>%
  group_by(status) %>%
  summarise(avg_wind = mean(wind)) %>%
  data.frame() %>%
  table_id_inject(id = c('#bgred'),
     conditions = c('== "tropical depression"'))
     
     
# Table object
table(mtcars$cyl, mtcars$disp) %>%
  table_id_inject(id = c('#bgred'), 
                conditions = c('>= 3'))
  

highlightHTML documentation built on April 21, 2020, 5:06 p.m.