setClass("defaultModelObjectProto", representation(name = "character"))
if (!isGeneric("modifyModel")) {
if (is.function("modifyModel"))
fun <- modifyModel
else
fun <- function(object, action, name, name.1, name.2, ...)
standardGeneric("modifyModel")
setGeneric("modifyModel", fun)
}
setMethod("modifyModel", signature(object = "defaultModelObjectProto"),
function(object, action, name, name.1, name.2, ...)
{
args <- list(...)
FactorVertices <- NULL
FactorEdges <- NULL
f <- function(type) if(is.null(type)) "" else paste("(", type, ")")
if (action == "dropEdge") {
message(paste("Should return an object with the edge from",
name.1, f(args$from.type), "to", name.2, f(args$to.type),
"deleted from the argument object"))
} else if (action == "addEdge") {
message(paste("Should return an object with the edge from",
name.1, f(args$from.type), "to", name.2, f(args$to.type),
"added to the argument object"))
} else if (action == "dropVertex") {
message(paste("Should return an object with the vertex",
name, f(args$type),
"deleted from the argument object"))
if (!is.null(args$Arguments) && (args$index > 0)
&& !is.null(args$Arguments$factorVertexList)
&& !is.null(args$Arguments$vertexList)) {
x <- (args$Arguments$factorVertexList)
factors <- lapply(x, function(i) i@vertex.indices)
types <- lapply(x, function(i) class(i))
factors <- lapply(factors, function(x) x[x != args$index])
if (!(is.null(factors))) {
result <- returnFactorVerticesAndEdges(
args$Arguments$vertexList, factors, types,
factorClasses = validFactorClasses())
FactorVertices <- result$FactorVertices
FactorEdges <- result$FactorEdges
}
}
} else if (action == "addVertex") {
message(paste("Should return an object with the vertex",
name, f(args$type), args$index,
"added to the argument object"))
}
return(list(object = object,
FactorVertices = FactorVertices,
FactorEdges = FactorEdges))
})
Run the code above in your browser using DataLab