This is a programmer's utility function to check whether the argument is a vector or factor of the correct length.
check.anyvector(v, npoints = NULL, fatal = TRUE, things = "data points",
naok = FALSE, warn = FALSE, vname, oneok = FALSE)
The argument to be checked.
The required length of v
.
Logical value indicating whether to stop with an error message
if v
does not satisfy all requirements.
Character string describing what the entries of v
should
correspond to.
Logical value indicating whether NA
values are permitted.
Logical value indicating whether to issue a warning
if v
does not satisfy all requirements.
Character string giving the name of v
to be used in messages.
Logical value indicating whether v
is permitted to have
length 1.
A logical value indicating whether all the requirements were
satisfied. If FALSE
, then this value has an attribute
"whinge"
, a character string describing the requirements that
were not satisfied.
This function checks whether v
is a vector or factor with
length equal to npoints
(or length equal to 1 if
oneok=TRUE
), not containing any NA
values (unless
naok=TRUE
).
If these requirements are all satisfied, the result is the logical
value TRUE
.
If not, then if fatal=TRUE
(the default), an error occurs;
if fatal=FALSE
, the result is the logical value FALSE
with an attribute describing the requirement that was not satisfied.
# NOT RUN {
z <- factor(1:10)
check.anyvector(z, 5, fatal=FALSE)
y <- z[1]
check.anyvector(y, 5, oneok=TRUE)
# }
Run the code above in your browser using DataLab