Skip to content

Commit 7203e42

Browse files
committed
Moved layer name check into its own function.
1 parent ab3c5de commit 7203e42

2 files changed

Lines changed: 21 additions & 13 deletions

File tree

DESCRIPTION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: ergm.multi
2-
Version: 0.3.0-4281
3-
Date: 2026-03-21
2+
Version: 0.3.0-4285
3+
Date: 2026-03-22
44
Title: Fit, Simulate and Diagnose Exponential-Family Models for Multiple or Multilayer Networks
55
Authors@R: c(person(c("Pavel", "N."), "Krivitsky", role=c("aut","cre"), email="pavel@statnet.org", comment=c(ORCID="0000-0002-9101-3362")),
66
person(c("Mark", "S."), "Handcock", role=c("ctb"), email="handcock@stat.ucla.edu"),

R/multilayer.R

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)