diff --git a/R/mully_edge.R b/R/mully_edge.R index 1fb388d..0100405 100644 --- a/R/mully_edge.R +++ b/R/mully_edge.R @@ -58,7 +58,7 @@ getEdgeAttributes<-function(g,nodeStart,nodeDest){ stop("Invalid Arguments") } edgeList=as.data.frame(get.edgelist(g),stringsAsFactors = FALSE) - attributes=as.data.frame(get.edge.attribute(g),stringsAsFactors = FALSE) + attributes=as.data.frame(lapply(edge_attr(g),I),stringsAsFactors = FALSE) edgeAttributes=cbind(edgeList,attributes) if(missing(nodeStart) && missing(nodeDest)){ return(edgeAttributes) @@ -121,6 +121,15 @@ addEdge <- function(g, nodeStart, nodeDest, attributes) { g <- set.edge.attribute(g, key, index = idEdge, attributes[[key]]) } + + # attributes of type list that were not specified in 'attributes' should be NULL instead of NA + edgeAttributes = edge_attr(g, index=idEdge) + for (key in names(edgeAttributes)) { + if (is.list(edgeAttributes[[key]]) && is.na(edgeAttributes[[key]])) { + g <- set.edge.attribute(g, key, index = idEdge, list(NULL)) + } + } + #name the class class(g) = c("mully",class(g)) return(g) diff --git a/R/mully_node.R b/R/mully_node.R index 9af68ca..8fdbfbe 100644 --- a/R/mully_node.R +++ b/R/mully_node.R @@ -105,6 +105,14 @@ addNode <- function(g, nodeName, layerName, attributes = NA) { } } + # attributes of type list that were not specified in 'attributes' should be NULL instead of NA + nodeAttributes = vertex_attr(g, index=idNode) + for (key in names(nodeAttributes)) { + if (is.list(nodeAttributes[[key]]) && is.na(nodeAttributes[[key]])) { + g <- set.vertex.attribute(g, key, index = idNode, list(NULL)) + } + } + #name the class class(g) = c("mully",class(g)) return(g) @@ -167,7 +175,7 @@ getNodeAttributes<-function(g,nameNode,layerByName=FALSE){ if(missing(g) || !is.mully(g)){ stop("Invalid Arguments") } - attributes=as.data.frame(get.vertex.attribute(g),stringsAsFactors = FALSE) + attributes=as.data.frame(lapply(vertex_attr(g),I),stringsAsFactors = FALSE) if(layerByName==TRUE){ attributes$n=g$layers$Name[attributes$n] } @@ -180,23 +188,13 @@ getNodeAttributes<-function(g,nameNode,layerByName=FALSE){ return(attributes[which(attributes$name==nameNode),]) } - getIDCommonDF<-function(df,df1){ - #Get the common rows - common=merge.data.frame(df,df1) - #No Common Rows - if(dim(common)[1]==0){ + common <- merge.data.frame( + cbind(rid=rownames(df), df), + df1 + ) + if (nrow(common) == 0) { return(NULL) } - rownb=dim(df)[1] - id=c() - for(i in 1:dim(common)[1]){ - for(j in 1:rownb){ - test=(df[j,]==common[i,]) - if(!is.na(test) && !FALSE%in%test){ - id<-append(id,rownames(df)[j]) - } - } - } - return(id) + common$rid } diff --git a/R/mully_visualization.R b/R/mully_visualization.R index ed0c118..dad094c 100644 --- a/R/mully_visualization.R +++ b/R/mully_visualization.R @@ -11,7 +11,7 @@ getRandomLayout <- function(g) { g2 = g for (i in 1:getLayersCount(g2)) { layer = getLayerByID(g, i) - if (is.null(layer) || is.na(layer)) + if (length(layer) == 0) next repeat { @@ -30,7 +30,7 @@ getScaledLayout <- function(g) { g2 = g for (i in 1:getLayersCount(g2)) { layer = getLayerByID(g, i) - if (is.null(layer) || is.na(layer)) + if (length(layer) == 0) next xs = (1:length(layer)) * 8 / length(layer)