updateEdgeAttributes: Update edge attributes

View source: R/RCX-NodeEdgeNetworkAttributes.R

updateEdgeAttributesR Documentation

Update edge attributes

Description

This functions add edge attributes in the form of a EdgeAttributes object to an RCX or an other EdgeAttributes object.

Usage

updateEdgeAttributes(
  x,
  edgeAttributes,
  replace = TRUE,
  stopOnDuplicates = FALSE,
  ...
)

## S3 method for class 'EdgeAttributesAspect'
updateEdgeAttributes(
  x,
  edgeAttributes,
  replace = TRUE,
  stopOnDuplicates = FALSE,
  ...
)

## S3 method for class 'RCX'
updateEdgeAttributes(
  x,
  edgeAttributes,
  replace = TRUE,
  stopOnDuplicates = FALSE,
  checkReferences = TRUE,
  ...
)

Arguments

x

RCX or EdgeAttributes object; (to which the new edge attributes will be added)

edgeAttributes

EdgeAttributes object; (the new aspect, that will be added)

replace

logical; if existing values are updated (or ignored)

stopOnDuplicates

logical; whether to stop, if duplicates in propertyOf and name (and subnetworkId if present) column are found

...

additional parameters

checkReferences

logical; whether to check if references to other aspects are present in the RCX object

Details

Edges may have additional attributes besides a name and a representation, and are represented as EdgeAttributes objects. EdgeAttributes objects can be added to an RCX or an other EdgeAttributes object. The propertyOf parameter references the Edges ids to which the attributes belong to. When adding an EdgeAttributes object to an RCX object, those ids must be present in the Edges aspect, otherwise an error is raised.

In the case, that a EdgeAttributes object is added to an other, or the RCX object already contains a EdgeAttributes object, some attributes might be present in both. By default, the attributes are updated with the values of the latest one. This can prevented by setting the replace parameter to FALSE, in that case only new attributes are added and the existing attributes remain untouched.

Furthermore, if duplicated attributes are considered as a preventable mistake, an error can be raised by setting stopOnDuplicates to TRUE. This forces the function to stop and raise an error, if duplicated attributes are present.

Value

EdgeAttributes or RCX object with added node attributes

See Also

NodeAttributes, NetworkAttributes

Examples

## For EdgeAttributesAspects: 
## prepare some aspects:
edgeAttributes = createEdgeAttributes(
  propertyOf=c(0,0,0,0),
  name=c("A","A","B","B"),
  value=list(c("a1","a2"),
             "a with subnetwork",
             "b",
             "b with subnetwork"),
  isList=c(TRUE,FALSE,TRUE,FALSE),
  subnetworkId=c(NA,1,NA,1)
)

## A is updated, C is new 
edgeAttributes2 = createEdgeAttributes(
  propertyOf=c(0,0,0),
  name=c("A","A","C"),
  value=list("new a",
             "new a with subnetwork",
             c(1,2)),
  subnetworkId=c(NA,1,NA)
)

## Simply update with new values
edgeAttributes3 = updateEdgeAttributes(edgeAttributes, edgeAttributes2)

## Ignore already present keys
edgeAttributes3 = updateEdgeAttributes(edgeAttributes, edgeAttributes2, 
                                       replace=FALSE)

## Raise an error if duplicate keys are present
try(updateEdgeAttributes(edgeAttributes, edgeAttributes2, 
                         stopOnDuplicates=TRUE))
## =>ERROR: 
## Elements of "propertyOf", "name" and "subnetworkId" (in updateEdgeAttributes)
## must not contain duplicates!

## For RCX
## prepare RCX object:
nodes = createNodes(name = c("a","b","c","d","e","f"))
edges = createEdges(source=c(1,2,0,0,0,2), 
                    target=c(2,3,1,2,5,4))
rcx = createRCX(nodes, edges)
cySubNetworks = createCySubNetworks(
  id = c(1,2),
  nodes = list("all", c(1,2,3)),
  edges = list("all", c(0,2))                    
)
rcx = updateCySubNetworks(rcx, cySubNetworks)

## add the edge attributes
rcx = updateEdgeAttributes(rcx, edgeAttributes)

## add additional edge attributes and update existing
rcx = updateEdgeAttributes(rcx, edgeAttributes2)

## create edge attributes for a not existing edge...
edgeAttributes3 = createEdgeAttributes(propertyOf=9, 
                                       name="A", 
                                       value="a")
## ...and try to add them
try(updateEdgeAttributes(rcx, edgeAttributes3))
## =>ERROR: 
## Provided IDs of "additionalAttributes$propertyOf" (in updateEdgeAttributes)
## don't exist in "rcx$edges$id"

frankkramer-lab/RCX documentation built on Feb. 4, 2023, 5:12 p.m.