@@ -54,6 +54,24 @@ network.layercount <- function(x, ...) {
5454}
5555
5656
57+ .check_layer_names <- function (nwl ) {
58+ if (is.null(nnames <- names(nwl ))) nnames <- as.character(seq_along(nwl ))
59+ else if (any(blank <- nnames == " " )) {
60+ message(" Layer(s) " , paste.and(which(blank )), " do not have specified names; they have been imputed with the corresponding layer number." )
61+ nnames [blank ] <- as.character(seq_along(nnames )[blank ])
62+ }
63+
64+ if (any(weird <-
65+ regexpr(" ^[0-9]+$" , nnames ) != - 1L # Names that are integers are potentially problematic,
66+ & nnames != seq_along(nnames ) # but not if they happen to match layer IDs.
67+ )) warning(" Using numeric layer names (" , paste.and(dQuote(nnames [weird ])), " ) is ambiguous." , immediate. = TRUE )
68+
69+ if (anyDuplicated(nnames )) stop(" Duplicate layer names." )
70+
71+ setNames(nwl , nnames )
72+ }
73+
74+
5775.layer_namemap <- function (nw ) {
5876 if (is(nw , " network" )) {
5977 nwl <- subnetwork_templates(nw , " .LayerID" , " .LayerName" , copy.ergmlhs = c())
@@ -513,17 +531,7 @@ Layer <- function(..., .symmetric=NULL, .bipartite=NULL, .active=NULL){
513531 }else stop(" Unrecognized format for multilayer specification. See help for information." )
514532
515533 # Perform some checks and imputations for layer names.
516- if (is.null(nnames <- names(nwl ))) nnames <- as.character(seq_along(nwl ))
517- else if (any(blank <- nnames == " " )) {
518- message(" Layer(s) " , paste.and(which(blank )), " do not have specified names; they have been imputed with the corresponding layer number." )
519- nnames [blank ] <- as.character(seq_along(nnames )[blank ])
520- }
521- if (any(weird <-
522- regexpr(" ^[0-9]+$" , nnames ) != - 1L # Names that are integers are potentially problematic,
523- & nnames != seq_along(nnames ) # but not if they happen to match layer IDs.
524- )) warning(" Using numeric layer names (" , paste.and(dQuote(nnames [weird ])), " ) is ambiguous." , immediate. = TRUE )
525- if (anyDuplicated(nnames )) stop(" Duplicate layer names." )
526- names(nwl ) <- nnames
534+ nwl <- .check_layer_names(nwl )
527535
528536 # # If network or vertex attributes differ from the first network, warn.
529537 .varying_attributes(nwl , list.network.attributes , get.network.attribute , " Network" , ignore = c(" directed" , " bipartite" , " mnext" , " .block_blacklist" ))
0 commit comments