is_hex_color: Does the character vector contain hex colors?

Description Usage Arguments Value Note Examples

Description

Checks that the input contains hexadecimal colors.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
assert_all_are_hex_colors(x, na_ignore = FALSE,
  severity = getOption("assertive.severity", "stop"))

assert_any_are_hex_colors(x, na_ignore = FALSE,
  severity = getOption("assertive.severity", "stop"))

assert_all_are_hex_colours(x, na_ignore = FALSE,
  severity = getOption("assertive.severity", "stop"))

assert_any_are_hex_colours(x, na_ignore = FALSE,
  severity = getOption("assertive.severity", "stop"))

is_hex_color(x)

is_hex_colour(x)

Arguments

x

Input to check.

na_ignore

A logical value. If FALSE, NA values cause an error; otherwise they do not. Like na.rm in many stats package functions, except that the position of the failing values does not change.

severity

How severe should the consequences of the assertion be? Either "stop", "warning", "message", or "none".

Value

A logical vector that is TRUE when the input contains hex colours.

Note

A string is considered to represent a hexadecimal colour when contains a hash followed by six hex values. That is, digits or the letters from a to f (case insensitive).

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
x <- c(
  "#012345", "#789abc", "#defDEF",  #ok
  "012345",                         #no hash
  "#g12345",                        #bad letter
  "#01 23 45",                      #contains spaces
  "#12345", "#1234567"              #wrong length
)
is_hex_color(x)
assert_any_are_hex_colors(x)
#These examples should fail.
assertive.base::dont_stop(assert_all_are_hex_colors(x))

assertive.data documentation built on May 2, 2019, 6:08 a.m.