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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
|
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/checkNames.R
\name{checkNames}
\alias{checkNames}
\alias{check_names}
\alias{assertNames}
\alias{assert_names}
\alias{testNames}
\alias{test_names}
\alias{expect_names}
\title{Check names to comply to specific rules}
\usage{
checkNames(
x,
type = "named",
subset.of = NULL,
must.include = NULL,
permutation.of = NULL,
identical.to = NULL,
disjunct.from = NULL,
what = "names"
)
check_names(
x,
type = "named",
subset.of = NULL,
must.include = NULL,
permutation.of = NULL,
identical.to = NULL,
disjunct.from = NULL,
what = "names"
)
assertNames(
x,
type = "named",
subset.of = NULL,
must.include = NULL,
permutation.of = NULL,
identical.to = NULL,
disjunct.from = NULL,
what = "names",
.var.name = vname(x),
add = NULL
)
assert_names(
x,
type = "named",
subset.of = NULL,
must.include = NULL,
permutation.of = NULL,
identical.to = NULL,
disjunct.from = NULL,
what = "names",
.var.name = vname(x),
add = NULL
)
testNames(
x,
type = "named",
subset.of = NULL,
must.include = NULL,
permutation.of = NULL,
identical.to = NULL,
disjunct.from = NULL,
what = "names"
)
test_names(
x,
type = "named",
subset.of = NULL,
must.include = NULL,
permutation.of = NULL,
identical.to = NULL,
disjunct.from = NULL,
what = "names"
)
expect_names(
x,
type = "named",
subset.of = NULL,
must.include = NULL,
permutation.of = NULL,
identical.to = NULL,
disjunct.from = NULL,
what = "names",
info = NULL,
label = vname(x)
)
}
\arguments{
\item{x}{[\code{character} || \code{NULL}]\cr
Names to check using rules defined via \code{type}.}
\item{type}{[character(1)]\cr
Type of formal check(s) to perform on the names.
\describe{
\item{unnamed:}{Checks \code{x} to be \code{NULL}.}
\item{named:}{Checks \code{x} for regular names which excludes names to be \code{NA} or empty (\code{""}).}
\item{unique:}{Performs checks like with \dQuote{named} and additionally tests for non-duplicated names.}
\item{strict:}{Performs checks like with \dQuote{unique} and additionally fails for names with UTF-8 characters and names which do not comply to R's variable name restrictions.
As regular expression, this is \dQuote{^[.]*[a-zA-Z]+[a-zA-Z0-9._]*$}.}
\item{ids:}{Same as \dQuote{strict}, but does not enforce uniqueness.}
}
Note that for zero-length \code{x}, all these name checks evaluate to \code{TRUE}.}
\item{subset.of}{[\code{character}]\cr
Names provided in \code{x} must be subset of the set \code{subset.of}.}
\item{must.include}{[\code{character}]\cr
Names provided in \code{x} must be a superset of the set \code{must.include}.}
\item{permutation.of}{[\code{character}]\cr
Names provided in \code{x} must be a permutation of the set \code{permutation.of}.
Duplicated names in \code{permutation.of} are stripped out and duplicated names in \code{x}
thus lead to a failed check.
Use this argument instead of \code{identical.to} if the order of the names is not relevant.}
\item{identical.to}{[\code{character}]\cr
Names provided in \code{x} must be identical to the vector \code{identical.to}.
Use this argument instead of \code{permutation.of} if the order of the names is relevant.}
\item{disjunct.from}{[\code{character}]\cr
Names provided in \code{x} must may not be present in the vector \code{disjunct.from}.}
\item{what}{[\code{character(1)}]\cr
Type of name vector to check, e.g. \dQuote{names} (default), \dQuote{colnames} or \dQuote{rownames}.}
\item{.var.name}{[\code{character(1)}]\cr
Name of the checked object to print in assertions. Defaults to
the heuristic implemented in \code{\link{vname}}.}
\item{add}{[\code{AssertCollection}]\cr
Collection to store assertion messages. See \code{\link{AssertCollection}}.}
\item{info}{[\code{character(1)}]\cr
Extra information to be included in the message for the testthat reporter.
See \code{\link[testthat]{expect_that}}.}
\item{label}{[\code{character(1)}]\cr
Name of the checked object to print in messages. Defaults to
the heuristic implemented in \code{\link{vname}}.}
}
\value{
Depending on the function prefix:
If the check is successful, the functions
\code{assertNames}/\code{assert_names} return
\code{x} invisibly, whereas
\code{checkNames}/\code{check_names} and
\code{testNames}/\code{test_names} return
\code{TRUE}.
If the check is not successful,
\code{assertNames}/\code{assert_names}
throws an error message,
\code{testNames}/\code{test_names}
returns \code{FALSE},
and \code{checkNames}/\code{check_names}
return a string with the error message.
The function \code{expect_names} always returns an
\code{\link[testthat]{expectation}}.
}
\description{
Performs various checks on character vectors, usually names.
}
\examples{
x = 1:3
testNames(names(x), "unnamed")
names(x) = letters[1:3]
testNames(names(x), "unique")
cn = c("Species", "Sepal.Length", "Sepal.Width", "Petal.Length", "Petal.Width")
assertNames(names(iris), permutation.of = cn)
}
\seealso{
Other attributes:
\code{\link{checkClass}()},
\code{\link{checkMultiClass}()},
\code{\link{checkNamed}()}
}
\concept{attributes}
|