cc {RNetica}R Documentation

Concatenates lists without stripping attributes

Description

OBSOLETE: This function was removed starting with RNetica 0.5 (it existed briefly as a workaround for a solution that change the object representation was the correct solution for.)

The base R function c() strips the attributes off of objects (particularly NeticaNode and NeticaBN objects). The function cc is a replacement which does not do that stripping.

Usage

cc(...)
## S3 method for class 'NeticaNode'
c(...)
## S3 method for class 'NeticaBN'
c(...)

Arguments

...

A list of objects. Generally it should be either NeticaNode or NeticaBN objects or lists of such objects.

Details

The base R c() function strips attributes from objects. For NeticaNode and NeticaBN objects, this removes the attributes that link the name to the Netica object and leaves just a string. This “feature” of S has been around since the days of the Blue Book and there is probably code that relies on this unexpected behavior.

The cc() function works around this by copying the arguments one at a time into a new list (slower but safer). Arguments which satisfy is(arg,"list") are treated as lists and add length(arg) elements to the lsit. All other arguments are treated as essentially lists of length 1, and the value is inserted in the appropriate place in the list.

The methods for NeticaNode and NeticaBN fix the c() function (which is generic) if the first argument is a singleton. Thus c(newNode,nodeList) and cc(newNode,nodeList) are identical. Note that these only fix half of the problem; c(nodeList,newNode) still calls the default method (or the method for lists) which strips the attributes of newNode. Instead use cc(nodeList,newNode) or c(nodeList,list(newNode))

Value

A list containing all of the values in the arguments. If there is a single, non-list argument, it will return a list with one element.

Author(s)

Russell Almond

See Also

NeticaNode,NeticaBN

Examples

## Not run: 
anet <- CreateNetwork("anet")

nodeList <- NewDiscreteNode(anet,paste("oldNode",1:3,sep=""))
newNode <- NewDiscreteNode(anet,"newNode")

l1 <- c(newNode,nodeList)               #A list of nodes
stopifnot(is.list(l1),length(l1)==4L,sapply(l1,is.NeticaNode))

l2 <- c(nodeList,newNode)               #Doesn't work!!!
stopifnot(!all(sapply(l2,is.NeticaNode)))

l2a <- cc(nodeList,newNode)               #Does work!!!
stopifnot(all(sapply(l2a,is.NeticaNode)))

l2b <- c(nodeList,list(newNode))         #As does this
stopifnot(all(sapply(l2b,is.NeticaNode)))

l3 <- c(newNode)                        #List with one element
stopifnot(is.list(l3),length(l3)==1L,sapply(l3,is.NeticaNode))

l4 <- c(newNode,nodeList[[1]],nodeList[[3]])                        
stopifnot(is.list(l4),length(l4)==3L,sapply(l4,is.NeticaNode))

l5 <- c(newNode,nodeList[2:3],nodeList[[1]])                        
stopifnot(is.list(l5),length(l5)==4L,sapply(l5,is.NeticaNode))

## End(Not run)


[Package RNetica version 0.5-4 Index]