Skip to content
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Depends:
methods,
R (>= 3.0.2)
Imports:
cli,
graphics,
grDevices,
magrittr,
Expand Down
211 changes: 105 additions & 106 deletions R/aaa-auto.R

Large diffs are not rendered by default.

93 changes: 30 additions & 63 deletions R/attributes.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@
#' graph_attr(g)
#' graph_attr(g, "name")
graph_attr <- function(graph, name) {
if (!is_igraph(graph)) {
stop("Not a graph object")
}
ensure_igraph(graph)
if (missing(name)) {
graph.attributes(graph)
} else {
Expand Down Expand Up @@ -112,26 +110,20 @@ graph_attr <- function(graph, name) {
#' g
#' plot(g)
set_graph_attr <- function(graph, name, value) {
if (!is_igraph(graph)) {
stop("Not a graph object")
}
ensure_igraph(graph)

.Call(R_igraph_mybracket3_set, graph, igraph_t_idx_attr, igraph_attr_idx_graph, name, value)
}

#' @export
graph.attributes <- function(graph) {
if (!is_igraph(graph)) {
stop("Not a graph object")
}
ensure_igraph(graph)
.Call(R_igraph_mybracket2_copy, graph, igraph_t_idx_attr, igraph_attr_idx_graph)
}

#' @export
"graph.attributes<-" <- function(graph, value) {
if (!is_igraph(graph)) {
stop("Not a graph object")
}
ensure_igraph(graph)
if (!is.list(value) || (length(value) > 0 && is.null(names(value))) ||
any(names(value) == "") || any(duplicated(names(value)))) {
stop("Value must be a named list with unique names")
Expand Down Expand Up @@ -163,9 +155,7 @@ graph.attributes <- function(graph) {
#' vertex_attr(g)
#' plot(g)
vertex_attr <- function(graph, name, index = V(graph)) {
if (!is_igraph(graph)) {
stop("Not a graph object")
}
ensure_igraph(graph)
if (missing(name)) {
if (missing(index)) {
vertex.attributes(graph)
Expand Down Expand Up @@ -246,9 +236,7 @@ set_vertex_attr <- function(graph, name, index = V(graph), value) {
}

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

if (is.null(value)) {
return(graph)
Expand Down Expand Up @@ -296,9 +284,7 @@ i_set_vertex_attr <- function(graph, name, index = V(graph), value, check = TRUE

#' @export
vertex.attributes <- function(graph, index = V(graph)) {
if (!is_igraph(graph)) {
stop("Not a graph object")
}
ensure_igraph(graph)

if (!missing(index)) {
index <- as.igraph.vs(graph, index)
Expand All @@ -317,9 +303,8 @@ vertex.attributes <- function(graph, index = V(graph)) {

#' @export
"vertex.attributes<-" <- function(graph, index = V(graph), value) {
if (!is_igraph(graph)) {
stop("Not a graph object")
}
ensure_igraph(graph)

if (!is.list(value) || (length(value) > 0 && is.null(names(value))) ||
any(names(value) == "") || any(duplicated(names(value)))) {
stop("Value must be a named list with unique names")
Expand Down Expand Up @@ -373,9 +358,8 @@ vertex.attributes <- function(graph, index = V(graph)) {
#' g
#' plot(g, edge.width = E(g)$weight)
edge_attr <- function(graph, name, index = E(graph)) {
if (!is_igraph(graph)) {
stop("Not a graph object")
}
ensure_igraph(graph)

if (missing(name)) {
if (missing(index)) {
edge.attributes(graph)
Expand Down Expand Up @@ -456,9 +440,7 @@ set_edge_attr <- function(graph, name, index = E(graph), value) {
}

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

if (is.null(value)) {
return(graph)
Expand Down Expand Up @@ -506,9 +488,7 @@ i_set_edge_attr <- function(graph, name, index = E(graph), value, check = TRUE)

#' @export
edge.attributes <- function(graph, index = E(graph)) {
if (!is_igraph(graph)) {
stop("Not a graph object")
}
ensure_igraph(graph)

if (!missing(index)) {
index <- as.igraph.es(graph, index)
Expand All @@ -527,9 +507,7 @@ edge.attributes <- function(graph, index = E(graph)) {

#' @export
"edge.attributes<-" <- function(graph, index = E(graph), value) {
if (!is_igraph(graph)) {
stop("Not a graph object")
}
ensure_igraph(graph)

if (!is.list(value) || (length(value) > 0 && is.null(names(value))) ||
any(names(value) == "") || any(duplicated(names(value)))) {
Expand Down Expand Up @@ -574,9 +552,7 @@ edge.attributes <- function(graph, index = E(graph)) {
#' g <- make_ring(10)
#' graph_attr_names(g)
graph_attr_names <- function(graph) {
if (!is_igraph(graph)) {
stop("Not a graph object")
}
ensure_igraph(graph)
res <- .Call(R_igraph_mybracket2_names, graph, igraph_t_idx_attr, igraph_attr_idx_graph)
if (is.null(res)) {
res <- character()
Expand All @@ -600,9 +576,8 @@ graph_attr_names <- function(graph) {
#' vertex_attr_names(g)
#' plot(g)
vertex_attr_names <- function(graph) {
if (!is_igraph(graph)) {
stop("Not a graph object")
}
ensure_igraph(graph)

res <- .Call(R_igraph_mybracket2_names, graph, igraph_t_idx_attr, igraph_attr_idx_vertex)

if (is.null(res)) {
Expand All @@ -626,9 +601,7 @@ vertex_attr_names <- function(graph) {
#' edge_attr_names(g)
#' plot(g)
edge_attr_names <- function(graph) {
if (!is_igraph(graph)) {
stop("Not a graph object")
}
ensure_igraph(graph)
res <- .Call(R_igraph_mybracket2_names, graph, igraph_t_idx_attr, igraph_attr_idx_edge)
if (is.null(res)) {
res <- character()
Expand All @@ -652,9 +625,8 @@ edge_attr_names <- function(graph) {
#' g2 <- delete_graph_attr(g, "name")
#' graph_attr_names(g2)
delete_graph_attr <- function(graph, name) {
if (!is_igraph(graph)) {
stop("Not a graph object")
}
ensure_igraph(graph)

name <- as.character(name)
if (!name %in% graph_attr_names(graph)) {
stop("No such graph attribute: ", name)
Expand Down Expand Up @@ -683,9 +655,8 @@ delete_graph_attr <- function(graph, name) {
#' g2 <- delete_vertex_attr(g, "name")
#' vertex_attr_names(g2)
delete_vertex_attr <- function(graph, name) {
if (!is_igraph(graph)) {
stop("Not a graph object")
}
ensure_igraph(graph)

name <- as.character(name)
if (!name %in% vertex_attr_names(graph)) {
stop("No such vertex attribute: ", name)
Expand Down Expand Up @@ -714,9 +685,8 @@ delete_vertex_attr <- function(graph, name) {
#' g2 <- delete_edge_attr(g, "name")
#' edge_attr_names(g2)
delete_edge_attr <- function(graph, name) {
if (!is_igraph(graph)) {
stop("Not a graph object")
}
ensure_igraph(graph)

name <- as.character(name)
if (!name %in% edge_attr_names(graph)) {
stop("No such edge attribute: ", name)
Expand Down Expand Up @@ -764,9 +734,8 @@ delete_edge_attr <- function(graph, name) {
#' neighbors(g, "a")
#'
is_named <- function(graph) {
if (!is_igraph(graph)) {
stop("Not a graph object")
}
ensure_igraph(graph)

"name" %in% vertex_attr_names(graph)
}

Expand Down Expand Up @@ -802,19 +771,17 @@ is_named <- function(graph) {
#' shortest_paths(g, 8, 2)
#'
is_weighted <- function(graph) {
if (!is_igraph(graph)) {
stop("Not a graph object")
}
ensure_igraph(graph)

"weight" %in% edge_attr_names(graph)
}

#' @rdname make_bipartite_graph
#' @family bipartite
#' @export
is_bipartite <- function(graph) {
if (!is_igraph(graph)) {
stop("Not a graph object")
}
ensure_igraph(graph)

"type" %in% vertex_attr_names(graph)
}

Expand Down
4 changes: 1 addition & 3 deletions R/basic.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ get.edge <- function(graph, id) {
"'ends' instead."
))

if (!is_igraph(graph)) {
stop("Not a graph object")
}
ensure_igraph(graph)

id <- as.numeric(id)
ec <- ecount(graph)
Expand Down
4 changes: 1 addition & 3 deletions R/bipartite.R
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,7 @@ bipartite_projection <- function(graph, types = NULL,
which = c("both", "true", "false"),
remove.type = TRUE) {
# Argument checks
if (!is_igraph(graph)) {
stop("Not a graph object")
}
ensure_igraph(graph)
types <- handle_vertex_type_arg(types, graph)
if (!is.null(probe1)) {
probe1 <- as.igraph.vs(graph, probe1) - 1
Expand Down
27 changes: 9 additions & 18 deletions R/centrality.R
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,8 @@ estimate_betweenness <- function(graph, vids = V(graph), directed = TRUE, cutoff
#'
betweenness <- function(graph, v = V(graph), directed = TRUE, weights = NULL,
nobigint = TRUE, normalized = FALSE, cutoff = -1) {
if (!is_igraph(graph)) {
stop("Not a graph object")
}
ensure_igraph(graph)

v <- as.igraph.vs(graph, v)
directed <- as.logical(directed)
if (is.null(weights) && "weight" %in% edge_attr_names(graph)) {
Expand Down Expand Up @@ -161,9 +160,8 @@ betweenness <- function(graph, v = V(graph), directed = TRUE, weights = NULL,
edge_betweenness <- function(graph, e = E(graph),
directed = TRUE, weights = NULL, cutoff = -1) {
# Argument checks
if (!is_igraph(graph)) {
stop("Not a graph object")
}
ensure_igraph(graph)

e <- as.igraph.es(graph, e)
directed <- as.logical(directed)
if (is.null(weights) && "weight" %in% edge_attr_names(graph)) {
Expand Down Expand Up @@ -262,9 +260,8 @@ closeness <- function(graph, vids = V(graph),
mode = c("out", "in", "all", "total"), weights = NULL,
normalized = FALSE, cutoff = -1) {
# Argument checks
if (!is_igraph(graph)) {
stop("Not a graph object")
}
ensure_igraph(graph)

vids <- as.igraph.vs(graph, vids)
mode <- switch(igraph.match.arg(mode),
"out" = 1,
Expand Down Expand Up @@ -1062,9 +1059,7 @@ harmonic_centrality <- harmonic_centrality_cutoff_impl
bonpow.dense <- function(graph, nodes = V(graph),
loops = FALSE, exponent = 1,
rescale = FALSE, tol = 1e-7) {
if (!is_igraph(graph)) {
stop("Not a graph object")
}
ensure_igraph(graph)

d <- as_adj(graph)
if (!loops) {
Expand Down Expand Up @@ -1240,9 +1235,7 @@ power_centrality <- function(graph, nodes = V(graph),
alpha.centrality.dense <- function(graph, nodes = V(graph), alpha = 1,
loops = FALSE, exo = 1, weights = NULL,
tol = 1e-7) {
if (!is_igraph(graph)) {
stop("Not a graph object")
}
ensure_igraph(graph)

exo <- rep(exo, length.out = vcount(graph))
exo <- matrix(exo, ncol = 1)
Expand Down Expand Up @@ -1280,9 +1273,7 @@ alpha.centrality.dense <- function(graph, nodes = V(graph), alpha = 1,
alpha.centrality.sparse <- function(graph, nodes = V(graph), alpha = 1,
loops = FALSE, exo = 1, weights = NULL,
tol = 1e-7) {
if (!is_igraph(graph)) {
stop("Not a graph object")
}
ensure_igraph(graph)

vc <- vcount(graph)

Expand Down
10 changes: 4 additions & 6 deletions R/centralization.R
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,8 @@ centr_degree_tmax <- function(graph = NULL, nodes = 0, mode = c("all", "out", "i
warning("centr_degree_tmax() will require an explicit value for its 'loops' argument from igraph 1.4.0. Assuming FALSE now.")
}
# Argument checks
if (!is.null(graph) && !is_igraph(graph)) {
stop("Not a graph object")
}
ensure_igraph(graph, optional = TRUE)

nodes <- as.integer(nodes)
mode <- switch(igraph.match.arg(mode),
"out" = 1,
Expand Down Expand Up @@ -207,9 +206,8 @@ centr_degree_tmax <- function(graph = NULL, nodes = 0, mode = c("all", "out", "i
#' centr_eigen(g, directed = FALSE)$centralization
centr_betw <- function(graph, directed = TRUE, nobigint = TRUE, normalized = TRUE) {
# Argument checks
if (!is_igraph(graph)) {
stop("Not a graph object")
}
ensure_igraph(graph)

directed <- as.logical(directed)
normalized <- as.logical(normalized)

Expand Down
Loading