check.named.vector

0th

Percentile

Check Whether Object Has Required Components

These functions check whether the object x has components with the required names, and does not have any unexpected components.

Keywords
error
Usage
check.named.vector(x, nam, context = "", namopt = character(0),
                   onError = c("fatal", "null"))

check.named.list(x, nam, context = "", namopt = character(0), onError = c("fatal", "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 x is being checked.

xtitle

Optional character string to be used when referring to x.

valid

Logical value indicating whether x belongs to the required class of objects.

type

Character string describing the required class of objects.

onError

Character string indicating what to do if x fails the checks.

fatal

Logical value indicating what to do if x fails the checks. If fatal=TRUE (the default), an error occurs.

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.

See Also

check.1.integer

Aliases
  • check.named.vector
  • check.named.list
  • check.named.thing
Examples
# NOT RUN {
  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)
# }
Documentation reproduced from package spatstat.utils, version 1.13-0, License: GPL (>= 2)

Community examples

Looks like there are no examples yet.