NetworkUserField {RNetica}R Documentation

Gets user definable fields associated with a Netica network.

Description

Netica provides a mechanism for associating user defined values with a network as a series of key/value pairs. The key must be a IDname and the value can be an arbitrary string (NetworkUserField) or arbitrary object (NetworkUserObj).

Usage

NetworkUserField(net, fieldname)
NetworkUserField(net, fieldname) <- value
NetworkUserObj(net, fieldname)
NetworkUserObj(net, fieldname) <- value
NetworkAllUserFields(net)

Arguments

net

A NeticaBN object indicating the network.

fieldname

A character scalar conforming to the IDname rules.

value

For NetworkUserField, an arbitrary character vector containing the new value. Only the first element is used. For NetworkUserObj, an arbitrary object which is serialized with dputToString and then saved.

Details

Netica contains a mechanism for associating user data with networks. In the Netica documentation, they note that only strings are really supported as only strings are portable across implementations. The function NetworkUserField provides direct access for storing strings.

The function NetworkUserObj wraps the call to NetworkUserField with a call to dputToString or dgetFromString to allow the serialization of arbitrary objects.

Value

The function NetworkUserField returns a character scalar with the value stored in the field fieldname, or NA if no such field exists.

The function NetworkUserObj returns an arbitrary object created by calling dgetFromString on the value stored in the field fieldname, or NULL if no such field exists. If the string cannot be interpreted as an R object, it generates an error.

The function NetworkAllUserFields returns a character vector containing all user data stored with the network (this will be the serialized versions of objects, not the objects themselves). The names of the result are the names of the fields.

Note

In his book Extending R John Chambers suggest serializing R objects through XML or JSON mechanisms rather than the older dump protocol. I may move to that later, although it will likely cause backwards compatability issues.

Author(s)

Russell Almond

References

http://norsys.com/onLineAPIManual/index.html GetNetUserField_bn(), SetNetUserField_bn(), GetNetNthUserField_bn()

See Also

NeticaBN, NetworkComment() NodeUserField, dputToString()

Examples

sess <- NeticaSession()
startSession(sess)

userNet <- CreateNetwork("UserNet", session=sess)
NetworkUserField(userNet,"Author") <- "Russell Almond"
NetworkUserField(userNet,"Status") <- "In Progress"

stopifnot(NetworkUserField(userNet,"Author")=="Russell Almond")
stopifnot(NetworkUserField(userNet,"Status")=="In Progress")

fields <- NetworkAllUserFields(userNet)
stopifnot(length(fields)==2)
stopifnot(all(!is.na(match(c("Russell Almond","In Progress"),fields))))
stopifnot(all(!is.na(match(c("Author","Status"),names(fields)))))

stopifnot(is.na(NetworkUserField(userNet,"gender")))
stopifnot(is.null(NetworkUserObj(userNet,"gender")))

x <- sample(1L:10L)
NetworkUserObj(userNet,"x") <- x
x1 <- NetworkUserObj(userNet,"x")
stopifnot(all(x==x1))

DeleteNetwork(userNet)
stopSession(sess)

[Package RNetica version 0.7-2 Index]