check.named.vector {spatstat.utils} | R Documentation |
Check Whether Object Has Required Components
Description
These functions check whether the object x
has
components with the required names, and does not have
any unexpected components.
Usage
check.named.vector(x, nam, context = "", namopt = character(0),
onError = c("fatal", "null"), xtitle=NULL)
check.named.list(x, nam, context = "", namopt = character(0),
onError = c("fatal", "null"), xtitle=NULL)
check.named.thing(x, nam, namopt = character(0),
xtitle = NULL, valid = TRUE, type = "object",
context = "", fatal = TRUE)
Arguments
x |
The object to be checked. |
nam |
Vector of character strings giving the names of all the components which must be present. |
namopt |
Vector of character strings giving the names of components which may optionally be present. |
context |
Character string describing the context in which |
xtitle |
Optional character string to be used when referring to |
valid |
Logical value indicating whether |
type |
Character string describing the required class of objects. |
onError |
Character string indicating what to do if |
fatal |
Logical value indicating what to do if |
Details
check.named.thing
checks whether x
has all the
required components, in the sense that names(x)
includes all the names in nam
,
and that every entry in names(x)
belongs to either nam
or
namopt
. If all these checks are true, the result is a
zero-length character vector. Otherwise, if fatal=TRUE
(the
default), an error occurs; otherwise the result is a character
vector describing the checks which failed.
check.named.vector
checks whether x
is a numeric vector
and check.named.list
checks whether x
is a list.
They then call check.named.thing
to check whether all the
required components are present. If all these checks are true, the result is
a reordered version of x
in which all the compulsory entries
appear first. Otherwise, if onError="fatal"
(the default)
an error occurs; otherwise the result is NULL
.
Value
check.named.vector
returns a numeric vector or NULL
.
check.named.list
returns a list or NULL
.
check.named.thing
returns a character vector.
Author(s)
Adrian Baddeley Adrian.Baddeley@curtin.edu.au.
See Also
Examples
z <- list(a=1, b=2, e=42)
check.named.list(z, c("a", "b"), namopt=c("c", "d", "e"))
check.named.thing(z, c("a", "b"), namopt=c("c", "d", "e"))
zz <- unlist(z)
check.named.vector(zz, c("a", "b"), namopt=c("c", "d", "e"))
check.named.thing(z, c("b", "c"), namopt=c("d", "e"), fatal=FALSE)