Skip to content

Commit 40c251e

Browse files
committed
as_tibble.network() now ensures that the returned tibble has all of the attrnames= columns, even if the network does not have those edge attributes.
references #49
1 parent 357ae8a commit 40c251e

1 file changed

Lines changed: 2 additions & 0 deletions

File tree

R/coercion.R

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,9 @@ as_tibble.network<-function(x,attrnames=(match.arg(unit)=="vertices"),na.rm=TRUE
268268
if(is.logical(attrnames) || is.numeric(attrnames))
269269
attrnames <- na.omit(setdiff(names(df), c(".tail", ".head", ".eid"))[attrnames])
270270

271+
# Keep only requested columns, but make sure all named columns are present.
271272
df <- df[intersect(c(".tail", ".head", ".eid", attrnames), names(df))]
273+
for(a in setdiff(attrnames, names(df))) df[[a]] <- rep(list(), nrow(df))
272274

273275
attr(df,"n")<-network.size(x)
274276
attr(df,"vnames")<-network.vertex.names(x)

0 commit comments

Comments
 (0)