Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 83 additions & 20 deletions R/attributes.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
##



#' Graph attributes of a graph
#'
#' @param graph Input graph.
Expand Down Expand Up @@ -174,11 +175,12 @@ vertex_attr <- function(graph, name, index = V(graph)) {
} else {
myattr <-
.Call(C_R_igraph_mybracket2, graph, igraph_t_idx_attr, igraph_attr_idx_vertex)[[as.character(name)]]
if (!missing(index)) {
if (is_complete_iterator(index)) {
myattr
} else {
index <- as.igraph.vs(graph, index)
myattr <- myattr[index]
myattr[index]
}
myattr
}
}

Expand Down Expand Up @@ -223,6 +225,7 @@ vertex_attr <- function(graph, name, index = V(graph)) {
#' of a subset of vertices.
#' @param value The new value of the attribute for all (or `index`)
#' vertices.
#' If `NULL`, the input is returned unchanged.
#' @return The graph, with the vertex attribute added or set.
#'
#' @aliases set.vertex.attribute
Expand All @@ -235,31 +238,58 @@ vertex_attr <- function(graph, name, index = V(graph)) {
#' g
#' plot(g)
set_vertex_attr <- function(graph, name, index = V(graph), value) {
i_set_vertex_attr(
graph = graph, name = name, index = index,
value = value
)
if (is_complete_iterator(index)) {
i_set_vertex_attr(graph = graph, name = name, value = value, check = FALSE)
} else {
i_set_vertex_attr(graph = graph, name = name, index = index, value = value)
}
}

i_set_vertex_attr <- function(graph, name, index = V(graph), value,
check = TRUE) {
i_set_vertex_attr <- function(graph, name, index = V(graph), value, check = TRUE) {
if (!is_igraph(graph)) {
stop("Not a graph object")
}

if (is.null(value)) {
return(graph)
}

single <- is_single_index(index)
complete <- is_complete_iterator(index)
if (!missing(index) && check) {
index <- as.igraph.vs(graph, index)
}
name <- as.character(name)
vc <- vcount(graph)

vattrs <- .Call(C_R_igraph_mybracket2, graph, igraph_t_idx_attr, igraph_attr_idx_vertex)

if (!complete && !(name %in% names(vattrs))) {
vattrs[[name]] <- value[rep.int(NA_integer_, vcount(graph))]
}

if (single) {
vattrs[[name]][[index]] <- value
} else {
vattrs[[name]][index] <- value
if (length(value) == 1) {
value_in <- rep(unname(value), length(index))
} else if (length(value) == length(index)) {
value_in <- unname(value)
} else {
stop(
"Length of new attribute value must be ",
if (length(index) != 1) "1 or ",
length(index),
", the number of target vertices, not ",
length(value)
)
}

if (complete) {
vattrs[[name]] <- value_in
} else {
vattrs[[name]][index] <- value_in
}
}
length(vattrs[[name]]) <- vc

.Call(C_R_igraph_mybracket2_set, graph, igraph_t_idx_attr, igraph_attr_idx_vertex, vattrs)
}
Expand Down Expand Up @@ -355,7 +385,7 @@ edge_attr <- function(graph, name, index = E(graph)) {
} else {
name <- as.character(name)
myattr <- .Call(C_R_igraph_mybracket2, graph, igraph_t_idx_attr, igraph_attr_idx_edge)[[name]]
if (is.null(index)) {
if (is_complete_iterator(index)) {
myattr
} else {
index <- as.igraph.es(graph, index)
Expand Down Expand Up @@ -405,6 +435,7 @@ edge_attr <- function(graph, name, index = E(graph)) {
#' a subset of edges.
#' @param value The new value of the attribute for all (or `index`)
#' edges.
#' If `NULL`, the input is returned unchanged.
#' @return The graph, with the edge attribute added or set.
#'
#' @aliases set.edge.attribute
Expand All @@ -417,26 +448,58 @@ edge_attr <- function(graph, name, index = E(graph)) {
#' g
#' plot(g)
set_edge_attr <- function(graph, name, index = E(graph), value) {
i_set_edge_attr(graph = graph, name = name, index = index, value = value)
if (is_complete_iterator(index)) {
i_set_edge_attr(graph = graph, name = name, value = value, check = FALSE)
} else {
i_set_edge_attr(graph = graph, name = name, index = index, value = value)
}
}

i_set_edge_attr <- function(graph, name, index = E(graph), value,
check = TRUE) {
i_set_edge_attr <- function(graph, name, index = E(graph), value, check = TRUE) {
if (!is_igraph(graph)) {
stop("Not a graph object")
}

if (is.null(value)) {
return(graph)
}

complete <- is_complete_iterator(index)
single <- is_single_index(index)
name <- as.character(name)
if (!missing(index) && check) index <- as.igraph.es(graph, index)
ec <- ecount(graph)
if (!missing(index) && check) {
index <- as.igraph.es(graph, index)
}

eattrs <- .Call(C_R_igraph_mybracket2, graph, igraph_t_idx_attr, igraph_attr_idx_edge)

if (!complete && !(name %in% names(eattrs))) {
eattrs[[name]] <- value[rep.int(NA_integer_, ecount(graph))]
}

if (single) {
eattrs[[name]][[index]] <- value
} else {
eattrs[[name]][index] <- value
if (length(value) == 1) {
value_in <- rep(unname(value), length(index))
} else if (length(value) == length(index)) {
value_in <- unname(value)
} else {
stop(
"Length of new attribute value must be ",
if (length(index) != 1) "1 or ",
length(index),
", the number of target edges, not ",
length(value)
)
}

if (complete) {
eattrs[[name]] <- value_in
} else {
eattrs[[name]][index] <- value_in
}
}
length(eattrs[[name]]) <- ec

.Call(C_R_igraph_mybracket2_set, graph, igraph_t_idx_attr, igraph_attr_idx_edge, eattrs)
}
Expand Down
2 changes: 1 addition & 1 deletion R/conversion.R
Original file line number Diff line number Diff line change
Expand Up @@ -1047,7 +1047,7 @@ as_long_data_frame <- function(graph) {
#' as.matrix(g, "adjacency")
#' as.matrix(g, "edgelist")
#' # use edge attribute "weight"
#' E(g)$weight <- rep(1:10, each = ecount(g))
#' E(g)$weight <- rep(1:10, length.out = ecount(g))
#' as.matrix(g, "adjacency", sparse = FALSE, attr = "weight")
#'
as.matrix.igraph <- function(x, matrix.type = c("adjacency", "edgelist"), ...) {
Expand Down
16 changes: 10 additions & 6 deletions R/interface.R
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,14 @@ add_edges <- function(graph, edges, ..., attr = list()) {
idx <- numeric()
}

eattrs <- .Call(C_R_igraph_mybracket2, graph, igraph_t_idx_attr, igraph_attr_idx_edge)
for (i in seq(attrs)) {
eattrs[[nam[i]]][idx] <- attrs[[nam[i]]]
attr <- attrs[[nam[i]]]
if (!is.null(attr)) {
graph <- set_edge_attr(graph, nam[[i]], idx, attr)
}
}

.Call(C_R_igraph_mybracket2_set, graph, igraph_t_idx_attr, igraph_attr_idx_edge, eattrs)
graph
}

#' Add vertices to a graph
Expand Down Expand Up @@ -148,12 +150,14 @@ add_vertices <- function(graph, nv, ..., attr = list()) {
idx <- numeric()
}

vattrs <- .Call(C_R_igraph_mybracket2, graph, igraph_t_idx_attr, igraph_attr_idx_vertex)
for (i in seq(attrs)) {
vattrs[[nam[i]]][idx] <- attrs[[nam[i]]]
attr <- attrs[[nam[i]]]
if (!is.null(attr)) {
graph <- set_vertex_attr(graph, nam[[i]], idx, attr)
}
}

.Call(C_R_igraph_mybracket2_set, graph, igraph_t_idx_attr, igraph_attr_idx_vertex, vattrs)
graph
}

#' Delete edges from a graph
Expand Down
2 changes: 1 addition & 1 deletion R/iterators.R
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ E <- function(graph, P = NULL, path = NULL, directed = TRUE) {
if (is.null(P) && is.null(path)) {
ec <- ecount(graph)
res <- seq_len(ec)
res <- set_complete_iterator(res)
} else if (!is.null(P)) {
on.exit(.Call(C_R_igraph_finalizer))
res <- .Call(
Expand All @@ -340,7 +341,6 @@ E <- function(graph, P = NULL, path = NULL, directed = TRUE) {
}

class(res) <- "igraph.es"
res <- set_complete_iterator(res)
add_vses_graph_ref(res, graph)
}

Expand Down
2 changes: 1 addition & 1 deletion R/structural.properties.R
Original file line number Diff line number Diff line change
Expand Up @@ -2118,7 +2118,7 @@ laplacian_matrix <- function(graph, normalized = FALSE, weights = NULL,
#' is_max_matching(g, m2)
#' is_max_matching(g, m3)
#'
#' V(g)$type <- c(FALSE, TRUE)
#' V(g)$type <- rep(c(FALSE, TRUE), 3)
#' print_all(g, v = TRUE)
#' max_bipartite_match(g)
#'
Expand Down
2 changes: 1 addition & 1 deletion man/as.matrix.igraph.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/matching.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion man/set_edge_attr.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion man/set_vertex_attr.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 12 additions & 17 deletions revdep/README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
# Revdeps

## Failed to check (9)

|package |version |error |warning |note |
|:---------|:-------|:-----|:-------|:----|
|DRviaSPCN |? | | | |
|genekitr |? | | | |
|immcp |? | | | |
|numbat |? | | | |
|Platypus |? | | | |
|NA |? | | | |
|tidySEM |? | | | |
|vivid |? | | | |
|NA |? | | | |

## New problems (3)
## New problems (12)

|package |version |error |warning |note |
|:------------|:-------|:------|:-------|:----|
|[causaleffect](problems.md#causaleffect)|1.3.15 |__+1__ |1 | |
|[R6causal](problems.md#r6causal)|0.7.0 | |__+1__ | |
|[backbone](problems.md#backbone)|2.1.1 |__+1__ | | |
|[deepdep](problems.md#deepdep)|0.4.1 |__+1__ | | |
|[egor](problems.md#egor)|1.22.12 |__+1__ | | |
|[GREMLINS](problems.md#gremlins)|0.2.0 |__+1__ |__+1__ |1 |
|[incidentally](problems.md#incidentally)|1.0.1 | |__+1__ | |
|[mstknnclust](problems.md#mstknnclust)|0.3.1 | |__+1__ | |
|[nat](problems.md#nat)|1.8.19 |__+1__ |1 | |
|[netmeta](problems.md#netmeta)|2.7-0 |__+1__ | |1 |
|[NetOrigin](problems.md#netorigin)|1.1-4 |__+1__ | | |
|[poppr](problems.md#poppr)|2.9.3 |__+1__ |1 |1 |
|[sfnetworks](problems.md#sfnetworks)|0.6.1 |__+1__ | | |
|[signnet](problems.md#signnet)|1.0.0 |__+1__ | |1 |

45 changes: 32 additions & 13 deletions revdep/cran.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,49 @@
## revdepcheck results

We checked 752 reverse dependencies (750 from CRAN + 2 from Bioconductor), comparing R CMD check results across CRAN and dev versions of this package.
We checked 12 reverse dependencies, comparing R CMD check results across CRAN and dev versions of this package.

* We saw 3 new problems
* We failed to check 7 packages
* We saw 12 new problems
* We failed to check 0 packages

Issues with CRAN packages are summarised below.

### New problems
(This reports the first line of each new failure)

* causaleffect
* backbone
checking tests ... ERROR

* deepdep
checking tests ... ERROR

* egor
checking tests ... ERROR

* GREMLINS
checking examples ... ERROR
checking re-building of vignette outputs ... WARNING

* incidentally
checking re-building of vignette outputs ... WARNING

* R6causal
* mstknnclust
checking re-building of vignette outputs ... WARNING

* nat
checking tests ... ERROR

* netmeta
checking examples ... ERROR

* NetOrigin
checking examples ... ERROR

* poppr
checking tests ... ERROR

* sfnetworks
checking tests ... ERROR

### Failed to check
* signnet
checking examples ... ERROR

* DRviaSPCN (NA)
* genekitr (NA)
* immcp (NA)
* numbat (NA)
* Platypus (NA)
* tidySEM (NA)
* vivid (NA)
Loading