IDname {RNetica} | R Documentation |
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.
is.IDname(x) as.IDname(x,prefix="y",maxlen=25)
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. |
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.
The argument is coerced into a character vector.
If any value begins with a nonalphabetic character, the
prefix
argument is prepended to all values.
All non-alphanumeric characters are converted to '_'.
Each value is truncated to maxlen
characters in length.
The truncation works by the following mechanism:
The string is truncated to length maxlen-3
.
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.
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.
A logical vector of the same length of x
.
This is primarily a utility for doing argument checking inside of functions that require a Netica IDname.
Russell Almond
http://norsys.com/onLineAPIManual/index.html
CreateNetwork()
, NewDiscreteNode()
,
NodeStates()
, NodeName()
,
NodeInputNames()
,
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") )