Learn R Programming

ggpattern (version 0.1.3)

check_default: Sanity check an argument value

Description

This is a milder, more explicit version of match.arg which gives a warning and returns a good default. match.arg() would throw errors which makes geom/pattern development a bit trickier.

Usage

check_default(
  x,
  options = NULL,
  default = NULL,
  type = NULL,
  prefix = "",
  verbose = FALSE
)

Arguments

x

argument value

options

valid options this value could take. If this is not NULL, then x is checked to be a member of this set. Default: NULL.

default

the default value to use if the argument fails the checks. If default is not NULL, then use it as the fallback value. If default is NULL and options is not NULL, then use the first value in options.

type

NULL, 'num' or 'char'

prefix

prefix of warning message.

verbose

default: FALSE

Value

original x value if there are no issues, otherwise the default if given, otherwise the first element in options.