check.anyvector: Check For Vector or Factor With Correct Length

View source: R/utilarg.R

check.anyvectorR Documentation

Check For Vector or Factor With Correct Length

Description

This is a programmer's utility function to check whether the argument is a vector or factor of the correct length.

Usage

     check.anyvector(v, npoints = NULL, fatal = TRUE, things = "data points",
                     naok = FALSE, warn = FALSE, vname, oneok = FALSE)

Arguments

v

The argument to be checked.

npoints

The required length of v.

fatal

Logical value indicating whether to stop with an error message if v does not satisfy all requirements.

things

Character string describing what the entries of v should correspond to.

naok

Logical value indicating whether NA values are permitted.

warn

Logical value indicating whether to issue a warning if v does not satisfy all requirements.

vname

Character string giving the name of v to be used in messages.

oneok

Logical value indicating whether v is permitted to have length 1.

Details

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.

Value

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.

Author(s)

\adrian

.

See Also

check.nvector, check.nmatrix, check.1.real, check.named.vector.

Examples

   z <- factor(letters[1:10])
   y <- z[1]
   check.anyvector(z, 5, fatal=FALSE)
   check.anyvector(y, 5, oneok=TRUE)
   check.anyvector(42, 5, fatal=FALSE)

spatstat/spatstat.utils documentation built on Oct. 25, 2023, 10:07 p.m.