Skip to content

Commit 887271b

Browse files
committed
Simplified some of the code in c.network.list() and fixed formatting.
1 parent 7182fe4 commit 887271b

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

R/network.list.R

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -130,30 +130,27 @@ c.network.list <- function(..., check_attr = TRUE) {
130130
dots <- list(...)
131131

132132
# Merge network lists without attributes
133-
lapply(dots, function(x) {
134-
attributes(x) <- NULL
135-
x
136-
}) -> l_networks
137-
rval <- do.call("c", l_networks)
133+
rval <- do.call("c", map(dots, unclass))
138134

139135
# Check attributes
140-
if(check_attr) {
136+
if (check_attr) {
141137
# Names of attributes to check with `all.equal()`
142138
attr_names <- c("coefficients", "control", "response",
143139
"formula", "constraints", "reference")
144-
for(an in attr_names) {
140+
for (an in attr_names) {
145141
al <- map(dots, ~ attr(.x, an))
146142
ok <- all_identical(al, all.equal)
147-
if(!ok) stop(paste0("network lists do not have equal values on attribute ", an))
143+
if (!ok) stop("network lists do not have equal values on attribute ", an)
148144
}
149145

150146
# Check if "stats" have identical columns
151147
l_stats <- map(dots, ~ attr(.x, "stats"))
152148
ok <- all_identical(
153-
lapply(l_stats, function(x) colnames(x)),
149+
map(l_stats, function(x) colnames(x)),
154150
.p = identical
155151
)
156-
if(!ok) stop("network lists do not have identical columns of 'stats' attribute")
152+
if (!ok) stop("network lists do not have identical columns of ",
153+
sQuote("stats"), " attribute")
157154
}
158155
# Return the list of networks with attributes merged or taken from the
159156
# first object

0 commit comments

Comments
 (0)