
Last chance! 50% off unlimited learning
Sale ends in
Check and return names
. If names are not
provided or are not unique, write a message and return
make.names
consistent with warn
and
unique
.
checkNames(x, warn=0, unique=TRUE,
avoid=character(0),
message0=head(deparse(substitute(x), 25), 2), ...)
an R object suitable for names
Numeric code for how to treat problems, consistent
with the argument warn
in options
:
Negative to ignore, 0 to save and print later, 1 to
print as they occur, 2 or greater to convert to errors.
logical: TRUE to check that names(x)
are
unique. Fix any duplicates with make.names
.
a vector of regular expressions to avoid adding in the
output of make.names
with a companion
replacement
when found.
Thus, length(avoid)
must be a nonnegative even
integer, with avoid[2*j-1]
providing the
pattern
for regexpr
and
sub
, and avoid[2*j]
providing
the replacement
. See the second example.
Base to prepend to any message
optional arguments for make.names
a character vector of the same length as x
. If any
problem is found, this character vector will have an
attribute message
describing the problem found.
Message checking considers unique
but ignores
warn
.
1. namex <- names(x)
2. Check per warn
and unique
3. Return an appropriate version of namex
names
make.names
options
for warn
# NOT RUN {
##
## 1. standard operation with no names
##
tst1 <- checkNames(1:2)
# check
tst1. <- make.names(character(2), unique=TRUE)
attr(tst1., 'message') <- paste(
"1:2: names = NULL; returning",
"make.names(character(length(x))), TRUE)")
# }
# NOT RUN {
all.equal(tst1, tst1.)
# }
# NOT RUN {
##
## 2. avoid=c('\\.0$', '\\.1$')
##
tst2 <-checkNames(1:2,
avoid=c('\\.0$', '.2',
'\\.1$', '.3') )
# check
tst2. <-c('X', 'X.3')
attr(tst2., 'message') <- paste(
"1:2: names = NULL; returning",
"make.names(character(length(x))), TRUE)")
# }
# NOT RUN {
all.equal(tst2, tst2.)
# }
Run the code above in your browser using DataLab