Checks that an argument is a single non-missing character string.
Meant for the labelling arguments across the suite - dataName,
captions, axis titles - where a vector or an NA would otherwise
travel unnoticed into printed output.
Usage
checkString(x, name = deparse(substitute(x)))Details
An optional argument that may also be NULL is guarded by the
caller, if (!is.null(dataName)) checkString(dataName), rather than
by a further argument here: whether the absence of a label is
admissible is a decision of the function, not of the check.
The empty string is accepted. It is a legitimate label, and a caller that needs a non-empty one says so itself.
Examples
dataName <- "smoking by sex"
checkString(dataName)
# all of these are rejected:
try(checkString(NA_character_)) # a missing label is not a label
#> Error : 'NA_character_' must be a single non-missing character string
try(checkString(c("a", "b"))) # length
#> Error : 'c("a", "b")' must be a single non-missing character string
try(checkString(42)) # type
#> Error : '42' must be a single non-missing character string
