IDname {RNetica}R Documentation

Tests to see if a string is a valid as a Netica Identifier.

Description

The function is.IDname() returns a logical vector indicating whether or not each element of x is a valid Netica identifier. The function is.IDname() attempts to massage the input value to conform to the IDname rules.

Usage

is.IDname(x)
as.IDname(x,prefix="y",maxlen=25)

Arguments

x

A character vector of possible identifier names.

prefix

A character scalar that provides an alphabetic prefix for names that start with an illegal character.

maxlen

The maximum number of characters to use in the converted name, which should be less than Netica's maximum of 30 characters.

Details

Netica identifiers (net names, node names, state names, and similar) are limited to 30 characters which must be a valid letter, number or the character '_'. The first character must be a letter. The function is.IDname() tests to see if a string conforms to these rules, and thus is a legal name.

The function as.IDname() attempts to coerce its argument into the IDname format by applying the following transformations.

  1. The argument is coerced into a character vector.

  2. If any value begins with a nonalphabetic character, the prefix argument is prepended to all values.

  3. All non-alphanumeric characters are converted to '_'.

  4. Each value is truncated to maxlen characters in length.

The truncation works by the following mechanism:

  1. The string is truncated to length maxlen-3.

  2. The UTF 8 values of the remaining characters is summed and the result is taken modulo 100 to provide a 2-digit hash code for the remaining characters.

  3. The hash code is appended to the end of the truncated string separated with an _.

This should result in strings which are likely, but not guaranteed to be unique if the difference between two names is only after the last maxlen-3 characters.

Note that although Netica allows variable names up to 30 characters in length, in some cases (particularly when stub variables are created after separating an edge from its parent) Netica creates new variable names by appending characters onto existing ones. That is why the recommended value for maxlen is set to 25.

Value

A logical vector of the same length of x.

Note

This is primarily a utility for doing argument checking inside of functions that require a Netica IDname.

Author(s)

Russell Almond

References

http://norsys.com/onLineAPIManual/index.html

See Also

CreateNetwork(), NewDiscreteNode(), NodeStates(), NodeName(), NodeInputNames(),

Examples

stopifnot(
is.IDname(c("aFish","Wanda1","feed me","fish_food","1more","US$",
                      "a123456789012345678901234567890")) ==
          c(TRUE,TRUE,FALSE,TRUE,FALSE,FALSE,FALSE),
as.IDname(c("aFish","Wanda1","feed me","fish_food","1more","US$",
                      "a123456789012345678901234567890")) ==
          c("aFish","Wanda1","feed_me","fish_food","y1more","US_",
                      "a123456789012345678901_25")
)

[Package RNetica version 0.7-2 Index]