html_tri: Format Numeric Data with HTML Arrows

Description Usage Arguments Value Author(s) Examples

Description

When producing numbers in R markdown documents, it can be nice to try and draw readers' attention to increases and decreases. The html_tri function takes a numeric vector, and returns a character vector of HTML strings, which will render in an (R) markdown document as numbers accompanied with a green 'upward' triangle for positive numbers, a red 'downward' triangle for negative ones, and a black square for numbers which are exactly 0 by default. The colours can be altered by passing valid CSS colour values to the colours argument, and the symbols by passing valid HTML character values to the symbols argument. The default values are in HTML decimal character codes.

If you'd only like to green/red triangles for some non-zero numbers, you can use the subset argument to pass a logical vector (the same) length as x to html_tri. This will mean that only elements of x will get a traingle when they are non-negative and subset is TRUE.

Usage

1
2
3
html_tri(x, format = round, subset = TRUE, symbols = c(up = "▲",
  down = "▼", nochange = "■"), colours = c(up = "green", down =
  "red", nochange = "black"))

Arguments

x

A numeric vector

format

A function used to format the numbers before the HTML for the triangles is added.

subset

A logical vector. Should elements of x get coloured arrows (as opposed to the symbol for 'nochange')?

symbols

The symbols to use for increases, decreases, and things not chaning respectively. Must a a vector of length 3, the entries having the names "up", "down", and "nochange"

colours

As above, but for the colours of the symbols

Value

A vector of character values, containing HTML so that they should render with green/red triangles in an HTML document. values in x.

Author(s)

Brendan Rocks rocks.brendan@gmail.com

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# This will output 'raw' HTML. To see the final result in an HTML markdown
# document, see the package vignette; vignette("brocks")

html_tri(runif(10))

# You could use other HTML symbols, even emojis if you like!
# These are HTML decimal codes (only unicode allowed in R packages), but
# you could use any valid characters (e.g. copy and paste)

html_tri(runif(10), symbols = c("up" = "😊", "down" = "😞",
  "nochange" = "😐"))

brendan-R/brocks documentation built on May 13, 2019, 5:07 a.m.