R/sanitization-enumeration.R

Defines functions check.graph.narcs check.graph.root.nodes check.enumeration.args

# sanitize the extra arguments passed to the graph enumerations.
check.enumeration.args = function(type, N, extra) {

  # check the number of root nodes.
  if (has.argument(type, "k", enumerations.extra.args))
    check.graph.root.nodes(extra[["k"]], N)

  # check the number of arcs.
  if (has.argument(type, "r", enumerations.extra.args))
    check.graph.narcs(extra[["r"]], N)

  # warn about and remove unused arguments.
  extra = check.unused.args(extra, enumerations.extra.args[[type]])

  return(extra)

}#CHECK.ENUMERATION.ARGS

# check the number of root nodes.
check.graph.root.nodes = function(k, N) {

  if (is.null(k))
    stop("unspecified number of root nodes.")

  if (!is.positive.integer(k))
    stop("the number of root nodes must be a positive integer.")
  if (k > max(N))
    warning("the number of root nodes is larger than the number of nodes.")

}#CHECK.GRAPH.ROOT.NODES

# check the number of arcs.
check.graph.narcs = function(r, N) {

  if (is.null(r))
    stop("unspecified number of arcs.")

  if (!is.non.negative.integer(r))
    stop("the number of arcs must be a positive integer.")
  if (r > choose(max(N), 2))
    warning("the number of arcs is larger than the maximum possible number of arcs.")

}#CHECK.GRAPH.NARCS

Try the bnlearn package in your browser

Any scripts or data that you put into this service are public.

bnlearn documentation built on Sept. 11, 2024, 8:27 p.m.