From 5741ef3a54db62d0c1456294eee47289308670cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABlle=20Salmon?= Date: Thu, 3 Sep 2026 14:02:51 +0200 Subject: [PATCH] chore: update minimal R version to R4.1.0 --- DESCRIPTION | 2 +- NAMESPACE | 1 - R/adjacency.R | 8 ++--- R/attributes.R | 24 +++++++-------- R/centralization.R | 8 ++--- R/community.R | 6 ++-- R/igraph-package.R | 25 +++++++++++----- R/interface.R | 24 +++++++-------- R/iterators.R | 46 ++++++++++++++--------------- R/layout.R | 12 ++++---- R/make.R | 6 ++-- R/old-0_1_1.R | 2 +- R/old-0_2.R | 2 +- R/old-0_5.R | 4 +-- R/old-0_6.R | 2 +- R/old-1_0_0.R | 2 +- R/old-1_5_0.R | 2 +- R/operators.R | 8 ++--- R/palette.R | 29 +++++++++--------- R/rewire.R | 10 +++---- R/scan.R | 4 +-- man/E.Rd | 2 +- man/V.Rd | 2 +- man/add_edges.Rd | 6 ++-- man/add_layout_.Rd | 4 +-- man/add_vertices.Rd | 6 ++-- man/as_membership.Rd | 4 +-- man/categorical_pal.Rd | 4 +-- man/centr_betw_tmax.Rd | 2 +- man/centr_clo_tmax.Rd | 2 +- man/centr_degree_tmax.Rd | 2 +- man/centr_eigen_tmax.Rd | 2 +- man/component_wise.Rd | 4 +-- man/delete_edge_attr.Rd | 2 +- man/delete_edges.Rd | 4 +-- man/delete_vertex_attr.Rd | 2 +- man/delete_vertices.Rd | 4 +-- man/diverging_pal.Rd | 19 ++++++------ man/each_edge.Rd | 2 +- man/edge.Rd | 6 ++-- man/edge_attr.Rd | 4 +-- man/edge_attr_names.Rd | 2 +- man/graph_from_adjacency_matrix.Rd | 8 ++--- man/gsize.Rd | 4 +-- man/igraph-es-indexing.Rd | 4 +-- man/igraph-vs-indexing2.Rd | 4 +-- man/keeping_degseq.Rd | 4 +-- man/layout_as_bipartite.Rd | 4 +-- man/path.Rd | 2 +- man/pipe.Rd | 19 ++++++++---- man/print.igraph.es.Rd | 10 +++---- man/print.igraph.vs.Rd | 6 ++-- man/rev.igraph.es.Rd | 2 +- man/rev.igraph.vs.Rd | 2 +- man/rewire.Rd | 4 +-- man/sample_.Rd | 2 +- man/scan_stat.Rd | 4 +-- man/sequential_pal.Rd | 6 ++-- man/set_edge_attr.Rd | 2 +- man/set_graph_attr.Rd | 2 +- man/set_vertex_attr.Rd | 2 +- man/unique.igraph.es.Rd | 2 +- man/unique.igraph.vs.Rd | 2 +- man/vertex_attr.Rd | 4 +-- man/vertex_attr_names.Rd | 4 +-- man/with_edge_.Rd | 2 +- man/with_vertex_.Rd | 2 +- tests/testthat/test-attributes.R | 24 +++++++-------- tests/testthat/test-cliques.R | 4 +-- tests/testthat/test-incidence.R | 24 +++++++-------- tests/testthat/test-layout.R | 6 ++-- tests/testthat/test-print-classic.R | 20 ++++++------- tests/testthat/test-rewire.R | 8 ++--- vignettes/igraph.Rmd | 18 +++++------ vignettes/igraph_ES.rmd | 18 +++++------ 75 files changed, 279 insertions(+), 262 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 0f2ae57119e..1d6caf6c772 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -35,7 +35,7 @@ URL: https://r.igraph.org/, https://igraph.org/, BugReports: https://github.com/igraph/rigraph/issues Depends: methods, - R (>= 4.0.0) + R (>= 4.1.0) Imports: cli, graphics, diff --git a/NAMESPACE b/NAMESPACE index 6735ed9b748..0470e051976 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -950,7 +950,6 @@ importFrom(graphics, xyinch ) importFrom(lifecycle,deprecated) -importFrom(magrittr,"%>%") importFrom(pkgconfig, get_config, set_config, diff --git a/R/adjacency.R b/R/adjacency.R index f17ba443814..6c173524077 100644 --- a/R/adjacency.R +++ b/R/adjacency.R @@ -173,15 +173,15 @@ graph.adjacency <- function( #' g1 <- sample( #' x = 0:1, size = 100, replace = TRUE, #' prob = c(0.9, 0.1) -#' ) %>% -#' matrix(ncol = 10) %>% +#' ) |> +#' matrix(ncol = 10) |> #' graph_from_adjacency_matrix() #' #' g2 <- sample( #' x = 0:5, size = 100, replace = TRUE, #' prob = c(0.9, 0.02, 0.02, 0.02, 0.02, 0.02) -#' ) %>% -#' matrix(ncol = 10) %>% +#' ) |> +#' matrix(ncol = 10) |> #' graph_from_adjacency_matrix(weighted = TRUE) #' E(g2)$weight #' diff --git a/R/attributes.R b/R/attributes.R index 13824155c1c..0d2d0a19677 100644 --- a/R/attributes.R +++ b/R/attributes.R @@ -379,7 +379,7 @@ graph_attr <- function(graph, name) { #' #' @export #' @examples -#' g <- make_ring(10) %>% +#' g <- make_ring(10) |> #' set_graph_attr("layout", layout_with_fr) #' g #' plot(g) @@ -442,8 +442,8 @@ graph.attributes <- function(graph) { #' #' @export #' @examples -#' g <- make_ring(10) %>% -#' set_vertex_attr("color", value = "red") %>% +#' g <- make_ring(10) |> +#' set_vertex_attr("color", value = "red") |> #' set_vertex_attr("label", value = letters[1:10]) #' vertex_attr(g, "label") #' vertex_attr(g) @@ -528,7 +528,7 @@ vertex_attr <- function(graph, name, index = NULL) { #' #' @export #' @examples -#' g <- make_ring(10) %>% +#' g <- make_ring(10) |> #' set_vertex_attr("label", value = LETTERS[1:10]) #' g #' plot(g) @@ -766,8 +766,8 @@ set_value_at <- function(value, idx, length_out) { #' #' @export #' @examples -#' g <- make_ring(10) %>% -#' set_edge_attr("weight", value = 1:10) %>% +#' g <- make_ring(10) |> +#' set_edge_attr("weight", value = 1:10) |> #' set_edge_attr("color", value = "red") #' g #' plot(g, edge.width = E(g)$weight) @@ -852,7 +852,7 @@ edge_attr <- function(graph, name, index = NULL) { #' #' @export #' @examples -#' g <- make_ring(10) %>% +#' g <- make_ring(10) |> #' set_edge_attr("label", value = LETTERS[1:10]) #' g #' plot(g) @@ -1052,8 +1052,8 @@ graph_attr_names <- function(graph) { #' #' @export #' @examples -#' g <- make_ring(10) %>% -#' set_vertex_attr("name", value = LETTERS[1:10]) %>% +#' g <- make_ring(10) |> +#' set_vertex_attr("name", value = LETTERS[1:10]) |> #' set_vertex_attr("color", value = rep("green", 10)) #' vertex_attr_names(g) #' plot(g) @@ -1082,7 +1082,7 @@ vertex_attr_names <- function(graph) { #' #' @export #' @examples -#' g <- make_ring(10) %>% +#' g <- make_ring(10) |> #' set_edge_attr("label", value = letters[1:10]) #' edge_attr_names(g) #' plot(g) @@ -1149,7 +1149,7 @@ delete_graph_attr <- function(graph, name) { #' #' @export #' @examples -#' g <- make_ring(10) %>% +#' g <- make_ring(10) |> #' set_vertex_attr("name", value = LETTERS[1:10]) #' vertex_attr_names(g) #' g2 <- delete_vertex_attr(g, "name") @@ -1189,7 +1189,7 @@ delete_vertex_attr <- function(graph, name) { #' #' @export #' @examples -#' g <- make_ring(10) %>% +#' g <- make_ring(10) |> #' set_edge_attr("name", value = LETTERS[1:10]) #' edge_attr_names(g) #' g2 <- delete_edge_attr(g, "name") diff --git a/R/centralization.R b/R/centralization.R index 5d9a3cd52c5..48a9cdd8cfa 100644 --- a/R/centralization.R +++ b/R/centralization.R @@ -478,7 +478,7 @@ centr_degree <- function( #' @examples #' # A BA graph is quite centralized #' g <- sample_pa(1000, m = 4) -#' centr_degree(g, normalized = FALSE)$centralization %>% +#' centr_degree(g, normalized = FALSE)$centralization |> #' `/`(centr_degree_tmax(g, loops = FALSE)) #' centr_degree(g, normalized = TRUE)$centralization centr_degree_tmax <- function( @@ -633,7 +633,7 @@ centr_betw <- function( #' @examples #' # A BA graph is quite centralized #' g <- sample_pa(1000, m = 4) -#' centr_betw(g, normalized = FALSE)$centralization %>% +#' centr_betw(g, normalized = FALSE)$centralization |> #' `/`(centr_betw_tmax(g)) #' centr_betw(g, normalized = TRUE)$centralization centr_betw_tmax <- function( @@ -793,7 +793,7 @@ centr_clo <- function( #' @examples #' # A BA graph is quite centralized #' g <- sample_pa(1000, m = 4) -#' centr_clo(g, normalized = FALSE)$centralization %>% +#' centr_clo(g, normalized = FALSE)$centralization |> #' `/`(centr_clo_tmax(g)) #' centr_clo(g, normalized = TRUE)$centralization centr_clo_tmax <- function( @@ -941,7 +941,7 @@ centr_eigen <- function( #' @examples #' # A BA graph is quite centralized #' g <- sample_pa(1000, m = 4) -#' centr_eigen(g, normalized = FALSE)$centralization %>% +#' centr_eigen(g, normalized = FALSE)$centralization |> #' `/`(centr_eigen_tmax(g)) #' centr_eigen(g, normalized = TRUE)$centralization centr_eigen_tmax <- function( diff --git a/R/community.R b/R/community.R index 783f7676000..5ddf79674e4 100644 --- a/R/community.R +++ b/R/community.R @@ -687,9 +687,9 @@ print.membership <- function(x, ...) print(unclass(x), ...) #' @export #' @examples #' ## Compare to the correct clustering -#' g <- (make_full_graph(10) + make_full_graph(10)) %>% +#' g <- (make_full_graph(10) + make_full_graph(10)) |> #' rewire(each_edge(p = 0.2)) -#' correct <- rep(1:2, each = 10) %>% as_membership() +#' correct <- rep(1:2, each = 10) |> as_membership() #' fc <- cluster_fast_greedy(g) #' compare(correct, fc) #' compare(correct, membership(fc)) @@ -701,7 +701,7 @@ as_membership <- function(x) add_class(x, "membership") print.communities <- function(x, ...) { noc <- if (!is.null(x$membership)) max(membership(x), 0) else NA mod <- if (!is.null(x$modularity)) { - modularity(x) %>% format(digits = 2) + modularity(x) |> format(digits = 2) } else { NA_real_ } diff --git a/R/igraph-package.R b/R/igraph-package.R index 71e6b0c0cbf..1a289d64408 100644 --- a/R/igraph-package.R +++ b/R/igraph-package.R @@ -2,16 +2,19 @@ #' @import methods ## usethis namespace: start #' @importFrom lifecycle deprecated -#' @importFrom magrittr %>% #' @import rlang ## usethis namespace: end NULL -#' Magrittr's pipes +#' Magrittr's pipe #' -#' igraph re-exports the `%>%` operator of magrittr, because -#' we find it very useful. Please see the documentation in the -#' `magrittr` package. +#' @description +#' `r lifecycle::badge("deprecated")` +#' +#' igraph used to re-export the `%>%` operator of magrittr. Now that R has its +#' own base pipe, `|>`, available since R 4.1.0, please use that instead. If +#' you still need `%>%` and its extra features (such as the `.` placeholder), +#' import it from the `magrittr` package yourself. #' #' @param lhs Left hand side of the pipe. #' @param rhs Right hand side of the pipe. @@ -21,11 +24,17 @@ NULL #' @export #' @name %>% #' @rdname pipe +#' @keywords internal #' @examples -#' make_ring(10) %>% -#' add_edges(c(1, 6)) %>% +#' make_ring(10) |> +#' add_edges(c(1, 6)) |> #' plot() -NULL +`%>%` <- function(lhs, rhs) { + lifecycle::deprecate_soft("2.4.0", "`%>%`()", "`|>`()") + lhs <- substitute(lhs) + rhs <- substitute(rhs) + eval.parent(as.call(list(quote(magrittr::`%>%`), lhs, rhs))) +} #' The igraph package #' diff --git a/R/interface.R b/R/interface.R index 59ce5d4178e..6c7d46bd546 100644 --- a/R/interface.R +++ b/R/interface.R @@ -128,14 +128,14 @@ add.edges <- function(graph, edges, ..., attr = list()) { #' @family functions for manipulating graph structure #' #' @examples -#' g <- make_empty_graph(n = 5) %>% +#' g <- make_empty_graph(n = 5) |> #' add_edges(c( #' 1, 2, #' 2, 3, #' 3, 4, #' 4, 5 -#' )) %>% -#' set_edge_attr("color", value = "red") %>% +#' )) |> +#' set_edge_attr("color", value = "red") |> #' add_edges(c(5, 1), color = "green") #' E(g)[[]] #' plot(g) @@ -194,9 +194,9 @@ add_edges <- function(graph, edges, ..., attr = list()) { #' #' @export #' @examples -#' g <- make_empty_graph() %>% -#' add_vertices(3, color = "red") %>% -#' add_vertices(2, color = "green") %>% +#' g <- make_empty_graph() |> +#' add_vertices(3, color = "red") |> +#' add_vertices(2, color = "green") |> #' add_edges(c( #' 1, 2, #' 2, 3, @@ -252,11 +252,11 @@ add_vertices <- function(graph, nv, ..., attr = list()) { #' #' @export #' @examples -#' g <- make_ring(10) %>% +#' g <- make_ring(10) |> #' delete_edges(seq(1, 9, by = 2)) #' g #' -#' g <- make_ring(10) %>% +#' g <- make_ring(10) |> #' delete_edges("10|1") #' g #' @@ -280,12 +280,12 @@ delete_edges <- function(graph, edges) { #' #' @export #' @examples -#' g <- make_ring(10) %>% +#' g <- make_ring(10) |> #' set_vertex_attr("name", value = LETTERS[1:10]) #' g #' V(g) #' -#' g2 <- delete_vertices(g, c(1, 5)) %>% +#' g2 <- delete_vertices(g, c(1, 5)) |> #' delete_vertices("B") #' g2 #' V(g2) @@ -316,8 +316,8 @@ delete_vertices <- function(graph, v) { #' ecount(g) #' #' # Number of edges in a G(n,p) graph -#' replicate(100, sample_gnp(10, 1 / 2), simplify = FALSE) %>% -#' vapply(gsize, 0) %>% +#' replicate(100, sample_gnp(10, 1 / 2), simplify = FALSE) |> +#' vapply(gsize, 0) |> #' hist() gsize <- function(graph) { ecount_impl( diff --git a/R/iterators.R b/R/iterators.R index 2cd55abea5c..9db0178ad54 100644 --- a/R/iterators.R +++ b/R/iterators.R @@ -280,7 +280,7 @@ inside_square_error <- function(fn_name, call = rlang::caller_env()) { #' V(g) #' #' # Vertex ids of a named graph -#' g2 <- make_ring(10) %>% +#' g2 <- make_ring(10) |> #' set_vertex_attr("name", value = letters[1:10]) #' V(g2) V <- function(graph) { @@ -382,7 +382,7 @@ unsafe_create_es <- function(graph, idx, es = NULL) { #' E(g) #' #' # Edges of a named graph -#' g2 <- make_ring(10) %>% +#' g2 <- make_ring(10) |> #' set_vertex_attr("name", value = letters[1:10]) #' E(g2) E <- function( @@ -865,8 +865,8 @@ set_single_index <- function(x, value = TRUE) { #' @family vertex and edge sequence operations #' @export #' @examples -#' g <- make_ring(10) %>% -#' set_vertex_attr("color", value = "red") %>% +#' g <- make_ring(10) |> +#' set_vertex_attr("color", value = "red") |> #' set_vertex_attr("name", value = LETTERS[1:10]) #' V(g) #' V(g)[[]] @@ -1038,8 +1038,8 @@ simple_es_index <- function(x, i, na_ok = FALSE) { #' #' # ----------------------------------------------------------------- #' # Select edges based on attributes -#' g <- sample_gnp(20, 3 / 20) %>% -#' set_edge_attr("weight", value = rnorm(gsize(.))) +#' g <- sample_gnp(20, 3 / 20) +#' g <- set_edge_attr(g, "weight", value = rnorm(gsize(g))) #' E(g)[[weight < 0]] #' #' # Indexing with a variable whose name matches the name of an attribute @@ -1484,7 +1484,7 @@ simple_es_index <- function(x, i, na_ok = FALSE) { #' V(g) #' #' # Named graphs -#' g2 <- make_ring(10) %>% +#' g2 <- make_ring(10) |> #' set_vertex_attr("name", value = LETTERS[1:10]) #' V(g2) #' @@ -1494,8 +1494,8 @@ simple_es_index <- function(x, i, na_ok = FALSE) { #' print(V(g3), full = TRUE) #' #' # Metadata -#' g4 <- make_ring(10) %>% -#' set_vertex_attr("name", value = LETTERS[1:10]) %>% +#' g4 <- make_ring(10) |> +#' set_vertex_attr("name", value = LETTERS[1:10]) |> #' set_vertex_attr("color", value = "red") #' V(g4)[[]] #' V(g4)[[2:5, 7:8]] @@ -1612,19 +1612,19 @@ print_igraph_vs_legacy <- function( #' E(g) #' #' # Named graphs -#' g2 <- make_ring(10) %>% +#' g2 <- make_ring(10) |> #' set_vertex_attr("name", value = LETTERS[1:10]) #' E(g2) #' #' # All edges in a long sequence #' g3 <- make_ring(200) #' E(g3) -#' E(g3) %>% print(full = TRUE) +#' E(g3) |> print(full = TRUE) #' #' # Metadata -#' g4 <- make_ring(10) %>% -#' set_vertex_attr("name", value = LETTERS[1:10]) %>% -#' set_edge_attr("weight", value = 1:10) %>% +#' g4 <- make_ring(10) |> +#' set_vertex_attr("name", value = LETTERS[1:10]) |> +#' set_edge_attr("weight", value = 1:10) |> #' set_edge_attr("color", value = "green") #' E(g4) #' E(g4)[[]] @@ -1906,7 +1906,7 @@ parse_op_args <- function(..., what, is_fun, as_fun, check_graph = TRUE) { } ## get the ids of all graphs - graph_id <- sapply(args, get_vs_graph_id) %>% + graph_id <- sapply(args, get_vs_graph_id) |> unique() if (length(graph_id) != 1) { @@ -1916,12 +1916,12 @@ parse_op_args <- function(..., what, is_fun, as_fun, check_graph = TRUE) { )) } - graphs <- args %>% - lapply(get_vs_graph) %>% + graphs <- args |> + lapply(get_vs_graph) |> drop_null() - addresses <- graphs %>% - sapply(function(x) x %&&% address(x)) %>% + addresses <- graphs |> + sapply(function(x) x %&&% address(x)) |> unique() if (check_graph && length(addresses) >= 2) { @@ -1987,7 +1987,7 @@ create_op_result <- function(parsed, result, class, args) { #' @examples #' g <- make_(ring(10), with_vertex_(name = LETTERS[1:10])) #' V(g)[1, 1:5, 1:10, 5:10] -#' V(g)[1, 1:5, 1:10, 5:10] %>% unique() +#' V(g)[1, 1:5, 1:10, 5:10] |> unique() unique.igraph.vs <- function(x, incomparables = FALSE, ...) { x[!duplicated(x, incomparables = incomparables, ...)] } @@ -2007,7 +2007,7 @@ unique.igraph.vs <- function(x, incomparables = FALSE, ...) { #' @examples #' g <- make_(ring(10), with_vertex_(name = LETTERS[1:10])) #' E(g)[1, 1:5, 1:10, 5:10] -#' E(g)[1, 1:5, 1:10, 5:10] %>% unique() +#' E(g)[1, 1:5, 1:10, 5:10] |> unique() unique.igraph.es <- function(x, incomparables = FALSE, ...) { x[!duplicated(x, incomparables = incomparables, ...)] } @@ -2206,7 +2206,7 @@ difference.igraph.es <- difference.igraph.vs #' @export #' @examples #' g <- make_(ring(10), with_vertex_(name = LETTERS[1:10])) -#' V(g) %>% rev() +#' V(g) |> rev() rev.igraph.vs <- function(x) { x[rev(seq_along(x))] } @@ -2223,7 +2223,7 @@ rev.igraph.vs <- function(x) { #' @examples #' g <- make_(ring(10), with_vertex_(name = LETTERS[1:10])) #' E(g) -#' E(g) %>% rev() +#' E(g) |> rev() rev.igraph.es <- rev.igraph.vs #' Convert a vertex or edge sequence to an ordinary vector diff --git a/R/layout.R b/R/layout.R index 5c028fe8959..35f96239eb4 100644 --- a/R/layout.R +++ b/R/layout.R @@ -478,8 +478,8 @@ layout_ <- function(graph, layout, ...) { #' @export #' @family graph layouts #' @examples -#' (make_star(11) + make_star(11)) %>% -#' add_layout_(as_star(), component_wise()) %>% +#' (make_star(11) + make_star(11)) |> +#' add_layout_(as_star(), component_wise()) |> #' plot() add_layout_ <- function(graph, ..., overwrite = TRUE) { if (overwrite && "layout" %in% graph_attr_names(graph)) { @@ -587,8 +587,8 @@ print.igraph_layout_modifier <- function(x, ...) { #' @export #' @examples #' g <- make_ring(10) + make_ring(10) -#' g %>% -#' add_layout_(in_circle(), component_wise()) %>% +#' g |> +#' add_layout_(in_circle(), component_wise()) |> #' plot() component_wise <- function(merge_method = "dla") { args <- grab_args() @@ -716,8 +716,8 @@ normalize <- function( #' ) #' #' # Two columns -#' g %>% -#' add_layout_(as_bipartite()) %>% +#' g |> +#' add_layout_(as_bipartite()) |> #' plot() layout_as_bipartite <- function( graph, diff --git a/R/make.R b/R/make.R index 7f245ca01ea..1c930253056 100644 --- a/R/make.R +++ b/R/make.R @@ -995,7 +995,7 @@ make_ <- function(...) { #' block.sizes = c(10, 10) #' )) #' -#' blocky2 <- pref_matrix %>% +#' blocky2 <- pref_matrix |> #' sample_sbm(n = 20, block.sizes = c(10, 10)) #' @family games #' @family constructor modifiers @@ -1165,7 +1165,7 @@ simplified <- function() { #' frame.color = "#7fcdbb", #' name = LETTERS[1:10] #' ) -#' ) %>% +#' ) |> #' plot() with_vertex_ <- function(...) { args <- grab_args() @@ -1191,7 +1191,7 @@ with_vertex_ <- function(...) { #' color = "red", #' weight = rep(1:2, 5) #' ) -#' ) %>% +#' ) |> #' plot() with_edge_ <- function(...) { args <- grab_args() diff --git a/R/old-0_1_1.R b/R/old-0_1_1.R index c4b73244f2f..56ed88bc27d 100644 --- a/R/old-0_1_1.R +++ b/R/old-0_1_1.R @@ -11,6 +11,6 @@ oldsample_0_1_1 <- function() { list(1, character(0), numeric(0)), list(3, character(0), numeric(0)), list(6, character(0), numeric(0)) - ) %>% + ) |> structure(class = "igraph") } diff --git a/R/old-0_2.R b/R/old-0_2.R index eccdb823272..cf0c17d2cc8 100644 --- a/R/old-0_2.R +++ b/R/old-0_2.R @@ -14,6 +14,6 @@ oldsample_0_2 <- function() { list(bar = c("A", "B", "C")), list(foo = c("a", "b", "c")) ) - ) %>% + ) |> structure(class = "igraph") } diff --git a/R/old-0_5.R b/R/old-0_5.R index b4330913eee..e0435bc1e2f 100644 --- a/R/old-0_5.R +++ b/R/old-0_5.R @@ -10,11 +10,11 @@ oldsample_0_5 <- function() { seq(0, 3, by = 1), list( c(1, 0), - list() %>% + list() |> structure(names = character(0)), list(bar = c("A", "B", "C")), list(foo = c("a", "b", "c")) ) - ) %>% + ) |> structure(class = "igraph") } diff --git a/R/old-0_6.R b/R/old-0_6.R index 2de9ee3ad21..54854f53972 100644 --- a/R/old-0_6.R +++ b/R/old-0_6.R @@ -14,6 +14,6 @@ oldsample_0_6 <- function() { list(bar = c("A", "B", "C")), list(foo = c("a", "b", "c")) ) - ) %>% + ) |> structure(class = "igraph") } diff --git a/R/old-1_0_0.R b/R/old-1_0_0.R index c7c92f7381d..44d97075461 100644 --- a/R/old-1_0_0.R +++ b/R/old-1_0_0.R @@ -16,7 +16,7 @@ oldsample_1_0_0 <- function() { list(foo = c("a", "b", "c")) ), ..env.1.. - ) %>% + ) |> structure(class = "igraph") ..env.1..$.__igraph_version__. <- "0.8.0" ..env.1..$myid <- "0fb28c05-9cc1-4a24-ba62-f5c319a3051b" diff --git a/R/old-1_5_0.R b/R/old-1_5_0.R index dbf3832bc3e..9bbff9d30cf 100644 --- a/R/old-1_5_0.R +++ b/R/old-1_5_0.R @@ -16,7 +16,7 @@ oldsample_1_5_0 <- function() { list(foo = c("a", "b", "c")) ), ..env.1.. - ) %>% + ) |> structure(class = "igraph") # This will be reconstructed on demand. diff --git a/R/operators.R b/R/operators.R index 7b558ebcd61..ef2084d8212 100644 --- a/R/operators.R +++ b/R/operators.R @@ -1192,7 +1192,7 @@ compose <- function( #' #' @export #' @examples -#' g <- make_ring(10) %>% +#' g <- make_ring(10) |> #' set_edge_attr("color", value = "red") #' #' g <- g + edge(1, 5, color = "green") + @@ -1201,8 +1201,8 @@ compose <- function( #' #' E(g)[[]] #' -#' g %>% -#' add_layout_(in_circle()) %>% +#' g |> +#' add_layout_(in_circle()) |> #' plot() #' #' g <- make_ring(10) + edges(1:10) @@ -1292,7 +1292,7 @@ vertices <- vertex #' g <- make_star(11, center = 1) + path(2:11, 2) #' plot(g) #' -#' g <- make_empty_graph(directed = FALSE, n = 10) %>% +#' g <- make_empty_graph(directed = FALSE, n = 10) |> #' set_vertex_attr("name", value = letters[1:10]) #' #' g2 <- g + path("a", "b", "c", "d") diff --git a/R/palette.R b/R/palette.R index 2063fbad590..07e5276eb09 100644 --- a/R/palette.R +++ b/R/palette.R @@ -37,8 +37,8 @@ #' \preformatted{ #' library(igraphdata) #' data(karate) -#' karate <- karate %>% -#' add_layout_(with_fr()) %>% +#' karate <- karate |> +#' add_layout_(with_fr()) |> #' set_vertex_attr("size", value = 10) #' #' cl_k <- cluster_optimal(karate) @@ -92,11 +92,11 @@ categorical_pal <- function(n) { #' @examplesIf rlang::is_installed(c("igraphdata", "scales")) #' library(igraphdata) #' data(karate) -#' karate <- karate %>% -#' add_layout_(with_kk()) %>% +#' karate <- karate |> +#' add_layout_(with_kk()) |> #' set_vertex_attr("size", value = 10) #' -#' V(karate)$color <- scales::dscale(degree(karate) %>% cut(5), sequential_pal) +#' V(karate)$color <- scales::dscale(degree(karate) |> cut(5), sequential_pal) #' plot(karate) sequential_pal <- function(n) { stopifnot(n >= 0) @@ -169,22 +169,23 @@ sequential_pal <- function(n) { #' @examplesIf rlang::is_installed(c("igraphdata", "scales")) #' library(igraphdata) #' data(foodwebs) -#' fw <- foodwebs[[1]] %>% -#' induced_subgraph(V(.)[ECO == 1]) %>% -#' add_layout_(with_fr()) %>% -#' set_vertex_attr("label", value = seq_len(gorder(.))) %>% -#' set_vertex_attr("size", value = 10) %>% +#' fw <- foodwebs[[1]] +#' fw <- induced_subgraph(fw, V(fw)[ECO == 1]) +#' fw <- fw |> +#' add_layout_(with_fr()) |> +#' set_vertex_attr("label", value = seq_len(gorder(fw))) |> +#' set_vertex_attr("size", value = 10) |> #' set_edge_attr("arrow.size", value = 0.3) #' -#' V(fw)$color <- scales::dscale(V(fw)$Biomass %>% cut(10), diverging_pal) +#' V(fw)$color <- scales::dscale(V(fw)$Biomass |> cut(10), diverging_pal) #' plot(fw) #' #' data(karate) -#' karate <- karate %>% -#' add_layout_(with_kk()) %>% +#' karate <- karate |> +#' add_layout_(with_kk()) |> #' set_vertex_attr("size", value = 10) #' -#' V(karate)$color <- scales::dscale(degree(karate) %>% cut(5), diverging_pal) +#' V(karate)$color <- scales::dscale(degree(karate) |> cut(5), diverging_pal) #' plot(karate) diverging_pal <- function(n) { stopifnot(n > 0) diff --git a/R/rewire.R b/R/rewire.R index 775e449d68a..d175326347a 100644 --- a/R/rewire.R +++ b/R/rewire.R @@ -34,8 +34,8 @@ #' @export rewire #' @examples #' g <- make_ring(10) -#' g %>% -#' rewire(each_edge(p = 0.1, loops = FALSE)) %>% +#' g |> +#' rewire(each_edge(p = 0.1, loops = FALSE)) |> #' plot(layout = layout_in_circle) #' print_all(rewire(g, with = keeping_degseq(niter = vcount(g) * 10))) rewire <- function(graph, with) { @@ -70,8 +70,8 @@ rewire <- function(graph, with) { #' @keywords graphs #' @examples #' g <- make_ring(10) -#' g %>% -#' rewire(keeping_degseq(niter = 20)) %>% +#' g |> +#' rewire(keeping_degseq(niter = 20)) |> #' degree() #' print_all(rewire(g, with = keeping_degseq(niter = vcount(g) * 10))) keeping_degseq <- function(loops = FALSE, niter = 100) { @@ -127,7 +127,7 @@ rewire_keeping_degseq <- function(graph, loops, niter) { #' # Rewiring the start of each directed edge preserves the in-degree distribution #' # but not the out-degree distribution #' g <- sample_pa(1000) -#' g2 <- g %>% rewire(each_edge(mode = "in", multiple = TRUE, prob = 0.2)) +#' g2 <- g |> rewire(each_edge(mode = "in", multiple = TRUE, prob = 0.2)) #' degree(g, mode = "in") == degree(g2, mode = "in") each_edge <- function( prob, diff --git a/R/scan.R b/R/scan.R index a719650c8d1..fb80dc178cb 100644 --- a/R/scan.R +++ b/R/scan.R @@ -353,8 +353,8 @@ local_scan <- function( #' PA[3, 3] <- p_ij$q #' num_v <- sum(block_sizes) #' -#' tsg <- replicate(num_t - 1, P0, simplify = FALSE) %>% -#' append(list(PA)) %>% +#' tsg <- replicate(num_t - 1, P0, simplify = FALSE) |> +#' append(list(PA)) |> #' lapply(sample_sbm, n = num_v, block.sizes = block_sizes, directed = TRUE) #' #' scan_stat(graphs = tsg, k = 1, tau = 4, ell = 2) diff --git a/man/E.Rd b/man/E.Rd index 8340cee43cc..829bcc71de5 100644 --- a/man/E.Rd +++ b/man/E.Rd @@ -70,7 +70,7 @@ g <- make_ring(10) E(g) # Edges of a named graph -g2 <- make_ring(10) \%>\% +g2 <- make_ring(10) |> set_vertex_attr("name", value = letters[1:10]) E(g2) } diff --git a/man/V.Rd b/man/V.Rd index 968cdc0541a..e7a2eba80ce 100644 --- a/man/V.Rd +++ b/man/V.Rd @@ -61,7 +61,7 @@ g <- make_ring(10) V(g) # Vertex ids of a named graph -g2 <- make_ring(10) \%>\% +g2 <- make_ring(10) |> set_vertex_attr("name", value = letters[1:10]) V(g2) } diff --git a/man/add_edges.Rd b/man/add_edges.Rd index 01859f4dde3..c0064ef0c67 100644 --- a/man/add_edges.Rd +++ b/man/add_edges.Rd @@ -38,14 +38,14 @@ their values for the original edges of the graph are set to \code{NA}. } \examples{ -g <- make_empty_graph(n = 5) \%>\% +g <- make_empty_graph(n = 5) |> add_edges(c( 1, 2, 2, 3, 3, 4, 4, 5 - )) \%>\% - set_edge_attr("color", value = "red") \%>\% + )) |> + set_edge_attr("color", value = "red") |> add_edges(c(5, 1), color = "green") E(g)[[]] plot(g) diff --git a/man/add_layout_.Rd b/man/add_layout_.Rd index eacd658cfef..23bf9036ec8 100644 --- a/man/add_layout_.Rd +++ b/man/add_layout_.Rd @@ -21,8 +21,8 @@ The input graph, with the layout added. Add layout to graph } \examples{ -(make_star(11) + make_star(11)) \%>\% - add_layout_(as_star(), component_wise()) \%>\% +(make_star(11) + make_star(11)) |> + add_layout_(as_star(), component_wise()) |> plot() } \seealso{ diff --git a/man/add_vertices.Rd b/man/add_vertices.Rd index e54cd66e9d6..79643926623 100644 --- a/man/add_vertices.Rd +++ b/man/add_vertices.Rd @@ -32,9 +32,9 @@ their values for the original vertices of the graph are set to } \examples{ -g <- make_empty_graph() \%>\% - add_vertices(3, color = "red") \%>\% - add_vertices(2, color = "green") \%>\% +g <- make_empty_graph() |> + add_vertices(3, color = "red") |> + add_vertices(2, color = "green") |> add_edges(c( 1, 2, 2, 3, diff --git a/man/as_membership.Rd b/man/as_membership.Rd index 3ad183a4306..b0b77017cf5 100644 --- a/man/as_membership.Rd +++ b/man/as_membership.Rd @@ -19,9 +19,9 @@ come from an igraph clustering method. } \examples{ ## Compare to the correct clustering -g <- (make_full_graph(10) + make_full_graph(10)) \%>\% +g <- (make_full_graph(10) + make_full_graph(10)) |> rewire(each_edge(p = 0.2)) -correct <- rep(1:2, each = 10) \%>\% as_membership() +correct <- rep(1:2, each = 10) |> as_membership() fc <- cluster_fast_greedy(g) compare(correct, fc) compare(correct, membership(fc)) diff --git a/man/categorical_pal.Rd b/man/categorical_pal.Rd index 70aab393ba7..b4710e48bf0 100644 --- a/man/categorical_pal.Rd +++ b/man/categorical_pal.Rd @@ -26,8 +26,8 @@ mark categories, e.g. community membership. \preformatted{ library(igraphdata) data(karate) -karate <- karate %>% - add_layout_(with_fr()) %>% +karate <- karate |> + add_layout_(with_fr()) |> set_vertex_attr("size", value = 10) cl_k <- cluster_optimal(karate) diff --git a/man/centr_betw_tmax.Rd b/man/centr_betw_tmax.Rd index 6da3968daf7..93a9bea3f18 100644 --- a/man/centr_betw_tmax.Rd +++ b/man/centr_betw_tmax.Rd @@ -34,7 +34,7 @@ See \code{\link[=centralize]{centralize()}} for a summary of graph centralizatio \examples{ # A BA graph is quite centralized g <- sample_pa(1000, m = 4) -centr_betw(g, normalized = FALSE)$centralization \%>\% +centr_betw(g, normalized = FALSE)$centralization |> `/`(centr_betw_tmax(g)) centr_betw(g, normalized = TRUE)$centralization } diff --git a/man/centr_clo_tmax.Rd b/man/centr_clo_tmax.Rd index 93fbe09cde8..5ebb929b2f1 100644 --- a/man/centr_clo_tmax.Rd +++ b/man/centr_clo_tmax.Rd @@ -38,7 +38,7 @@ See \code{\link[=centralize]{centralize()}} for a summary of graph centralizatio \examples{ # A BA graph is quite centralized g <- sample_pa(1000, m = 4) -centr_clo(g, normalized = FALSE)$centralization \%>\% +centr_clo(g, normalized = FALSE)$centralization |> `/`(centr_clo_tmax(g)) centr_clo(g, normalized = TRUE)$centralization } diff --git a/man/centr_degree_tmax.Rd b/man/centr_degree_tmax.Rd index 7a6f8cae489..788e3e35a31 100644 --- a/man/centr_degree_tmax.Rd +++ b/man/centr_degree_tmax.Rd @@ -36,7 +36,7 @@ See \code{\link[=centralize]{centralize()}} for a summary of graph centralizatio \examples{ # A BA graph is quite centralized g <- sample_pa(1000, m = 4) -centr_degree(g, normalized = FALSE)$centralization \%>\% +centr_degree(g, normalized = FALSE)$centralization |> `/`(centr_degree_tmax(g, loops = FALSE)) centr_degree(g, normalized = TRUE)$centralization } diff --git a/man/centr_eigen_tmax.Rd b/man/centr_eigen_tmax.Rd index 86ce59f90da..1835100ce2b 100644 --- a/man/centr_eigen_tmax.Rd +++ b/man/centr_eigen_tmax.Rd @@ -39,7 +39,7 @@ See \code{\link[=centralize]{centralize()}} for a summary of graph centralizatio \examples{ # A BA graph is quite centralized g <- sample_pa(1000, m = 4) -centr_eigen(g, normalized = FALSE)$centralization \%>\% +centr_eigen(g, normalized = FALSE)$centralization |> `/`(centr_eigen_tmax(g)) centr_eigen(g, normalized = TRUE)$centralization } diff --git a/man/component_wise.Rd b/man/component_wise.Rd index 050e6882e4d..bf0be28ab19 100644 --- a/man/component_wise.Rd +++ b/man/component_wise.Rd @@ -21,8 +21,8 @@ of the graph. \examples{ g <- make_ring(10) + make_ring(10) -g \%>\% - add_layout_(in_circle(), component_wise()) \%>\% +g |> + add_layout_(in_circle(), component_wise()) |> plot() } \seealso{ diff --git a/man/delete_edge_attr.Rd b/man/delete_edge_attr.Rd index b36bdc028b0..8807154cc97 100644 --- a/man/delete_edge_attr.Rd +++ b/man/delete_edge_attr.Rd @@ -18,7 +18,7 @@ The graph, with the specified edge attribute removed. Delete an edge attribute } \examples{ -g <- make_ring(10) \%>\% +g <- make_ring(10) |> set_edge_attr("name", value = LETTERS[1:10]) edge_attr_names(g) g2 <- delete_edge_attr(g, "name") diff --git a/man/delete_edges.Rd b/man/delete_edges.Rd index ca7508c1fe2..5f5a18d789d 100644 --- a/man/delete_edges.Rd +++ b/man/delete_edges.Rd @@ -25,11 +25,11 @@ Delete edges from a graph } \examples{ -g <- make_ring(10) \%>\% +g <- make_ring(10) |> delete_edges(seq(1, 9, by = 2)) g -g <- make_ring(10) \%>\% +g <- make_ring(10) |> delete_edges("10|1") g diff --git a/man/delete_vertex_attr.Rd b/man/delete_vertex_attr.Rd index e971b91a0e0..331592a67b2 100644 --- a/man/delete_vertex_attr.Rd +++ b/man/delete_vertex_attr.Rd @@ -18,7 +18,7 @@ The graph, with the specified vertex attribute removed. Delete a vertex attribute } \examples{ -g <- make_ring(10) \%>\% +g <- make_ring(10) |> set_vertex_attr("name", value = LETTERS[1:10]) vertex_attr_names(g) g2 <- delete_vertex_attr(g, "name") diff --git a/man/delete_vertices.Rd b/man/delete_vertices.Rd index 5703eb9e502..2ae6568db12 100644 --- a/man/delete_vertices.Rd +++ b/man/delete_vertices.Rd @@ -22,12 +22,12 @@ Delete vertices from a graph } \examples{ -g <- make_ring(10) \%>\% +g <- make_ring(10) |> set_vertex_attr("name", value = LETTERS[1:10]) g V(g) -g2 <- delete_vertices(g, c(1, 5)) \%>\% +g2 <- delete_vertices(g, c(1, 5)) |> delete_vertices("B") g2 V(g2) diff --git a/man/diverging_pal.Rd b/man/diverging_pal.Rd index e0693488832..d5d846c0d37 100644 --- a/man/diverging_pal.Rd +++ b/man/diverging_pal.Rd @@ -27,22 +27,23 @@ colors. \dontshow{if (rlang::is_installed(c("igraphdata", "scales"))) withAutoprint(\{ # examplesIf} library(igraphdata) data(foodwebs) -fw <- foodwebs[[1]] \%>\% - induced_subgraph(V(.)[ECO == 1]) \%>\% - add_layout_(with_fr()) \%>\% - set_vertex_attr("label", value = seq_len(gorder(.))) \%>\% - set_vertex_attr("size", value = 10) \%>\% +fw <- foodwebs[[1]] +fw <- induced_subgraph(fw, V(fw)[ECO == 1]) +fw <- fw |> + add_layout_(with_fr()) |> + set_vertex_attr("label", value = seq_len(gorder(fw))) |> + set_vertex_attr("size", value = 10) |> set_edge_attr("arrow.size", value = 0.3) -V(fw)$color <- scales::dscale(V(fw)$Biomass \%>\% cut(10), diverging_pal) +V(fw)$color <- scales::dscale(V(fw)$Biomass |> cut(10), diverging_pal) plot(fw) data(karate) -karate <- karate \%>\% - add_layout_(with_kk()) \%>\% +karate <- karate |> + add_layout_(with_kk()) |> set_vertex_attr("size", value = 10) -V(karate)$color <- scales::dscale(degree(karate) \%>\% cut(5), diverging_pal) +V(karate)$color <- scales::dscale(degree(karate) |> cut(5), diverging_pal) plot(karate) \dontshow{\}) # examplesIf} } diff --git a/man/each_edge.Rd b/man/each_edge.Rd index 4b1a3bcc7d1..907614595a3 100644 --- a/man/each_edge.Rd +++ b/man/each_edge.Rd @@ -47,7 +47,7 @@ mean_distance(g) # Rewiring the start of each directed edge preserves the in-degree distribution # but not the out-degree distribution g <- sample_pa(1000) -g2 <- g \%>\% rewire(each_edge(mode = "in", multiple = TRUE, prob = 0.2)) +g2 <- g |> rewire(each_edge(mode = "in", multiple = TRUE, prob = 0.2)) degree(g, mode = "in") == degree(g2, mode = "in") } \seealso{ diff --git a/man/edge.Rd b/man/edge.Rd index 41ea5e5f37c..1f4fe502094 100644 --- a/man/edge.Rd +++ b/man/edge.Rd @@ -34,7 +34,7 @@ When deleting edges via \code{-}, all arguments of \code{edge()} (or \code{\link[=delete_edges]{delete_edges()}}. } \examples{ -g <- make_ring(10) \%>\% +g <- make_ring(10) |> set_edge_attr("color", value = "red") g <- g + edge(1, 5, color = "green") + @@ -43,8 +43,8 @@ g <- g + edge(1, 5, color = "green") + E(g)[[]] -g \%>\% - add_layout_(in_circle()) \%>\% +g |> + add_layout_(in_circle()) |> plot() g <- make_ring(10) + edges(1:10) diff --git a/man/edge_attr.Rd b/man/edge_attr.Rd index d1a412dc8db..8625c7df1c2 100644 --- a/man/edge_attr.Rd +++ b/man/edge_attr.Rd @@ -28,8 +28,8 @@ Query edge attributes of a graph } \examples{ -g <- make_ring(10) \%>\% - set_edge_attr("weight", value = 1:10) \%>\% +g <- make_ring(10) |> + set_edge_attr("weight", value = 1:10) |> set_edge_attr("color", value = "red") g plot(g, edge.width = E(g)$weight) diff --git a/man/edge_attr_names.Rd b/man/edge_attr_names.Rd index a3d288e3800..39f058f2f04 100644 --- a/man/edge_attr_names.Rd +++ b/man/edge_attr_names.Rd @@ -16,7 +16,7 @@ Character vector, the names of the edge attributes. List names of edge attributes } \examples{ -g <- make_ring(10) \%>\% +g <- make_ring(10) |> set_edge_attr("label", value = letters[1:10]) edge_attr_names(g) plot(g) diff --git a/man/graph_from_adjacency_matrix.Rd b/man/graph_from_adjacency_matrix.Rd index 4959fcba910..1df8d27cecd 100644 --- a/man/graph_from_adjacency_matrix.Rd +++ b/man/graph_from_adjacency_matrix.Rd @@ -153,15 +153,15 @@ gives the edge weights. g1 <- sample( x = 0:1, size = 100, replace = TRUE, prob = c(0.9, 0.1) -) \%>\% - matrix(ncol = 10) \%>\% +) |> + matrix(ncol = 10) |> graph_from_adjacency_matrix() g2 <- sample( x = 0:5, size = 100, replace = TRUE, prob = c(0.9, 0.02, 0.02, 0.02, 0.02, 0.02) -) \%>\% - matrix(ncol = 10) \%>\% +) |> + matrix(ncol = 10) |> graph_from_adjacency_matrix(weighted = TRUE) E(g2)$weight diff --git a/man/gsize.Rd b/man/gsize.Rd index 04561dd519f..1458bdda29b 100644 --- a/man/gsize.Rd +++ b/man/gsize.Rd @@ -28,8 +28,8 @@ gsize(g) ecount(g) # Number of edges in a G(n,p) graph -replicate(100, sample_gnp(10, 1 / 2), simplify = FALSE) \%>\% - vapply(gsize, 0) \%>\% +replicate(100, sample_gnp(10, 1 / 2), simplify = FALSE) |> + vapply(gsize, 0) |> hist() } \seealso{ diff --git a/man/igraph-es-indexing.Rd b/man/igraph-es-indexing.Rd index aa72a58666b..fd39668cd2f 100644 --- a/man/igraph-es-indexing.Rd +++ b/man/igraph-es-indexing.Rd @@ -118,8 +118,8 @@ E(g, path = d) # ----------------------------------------------------------------- # Select edges based on attributes -g <- sample_gnp(20, 3 / 20) \%>\% - set_edge_attr("weight", value = rnorm(gsize(.))) +g <- sample_gnp(20, 3 / 20) +g <- set_edge_attr(g, "weight", value = rnorm(gsize(g))) E(g)[[weight < 0]] # Indexing with a variable whose name matches the name of an attribute diff --git a/man/igraph-vs-indexing2.Rd b/man/igraph-vs-indexing2.Rd index 37df820b503..3d953fc9df5 100644 --- a/man/igraph-vs-indexing2.Rd +++ b/man/igraph-vs-indexing2.Rd @@ -29,8 +29,8 @@ attributes of the vertices in the sequence are printed as well. See \code{\link{[.igraph.vs}} for more about indexing vertex sequences. } \examples{ -g <- make_ring(10) \%>\% - set_vertex_attr("color", value = "red") \%>\% +g <- make_ring(10) |> + set_vertex_attr("color", value = "red") |> set_vertex_attr("name", value = LETTERS[1:10]) V(g) V(g)[[]] diff --git a/man/keeping_degseq.Rd b/man/keeping_degseq.Rd index 225e14316df..b4320e0e1ad 100644 --- a/man/keeping_degseq.Rd +++ b/man/keeping_degseq.Rd @@ -24,8 +24,8 @@ edges. } \examples{ g <- make_ring(10) -g \%>\% - rewire(keeping_degseq(niter = 20)) \%>\% +g |> + rewire(keeping_degseq(niter = 20)) |> degree() print_all(rewire(g, with = keeping_degseq(niter = vcount(g) * 10))) } diff --git a/man/layout_as_bipartite.Rd b/man/layout_as_bipartite.Rd index c02f8d368cc..573105b84bc 100644 --- a/man/layout_as_bipartite.Rd +++ b/man/layout_as_bipartite.Rd @@ -64,8 +64,8 @@ plot(g, ) # Two columns -g \%>\% - add_layout_(as_bipartite()) \%>\% +g |> + add_layout_(as_bipartite()) |> plot() } \seealso{ diff --git a/man/path.Rd b/man/path.Rd index 3c60a96028c..cc2d4b175c3 100644 --- a/man/path.Rd +++ b/man/path.Rd @@ -32,7 +32,7 @@ to \code{\link[=delete_edges]{delete_edges()}}. g <- make_star(11, center = 1) + path(2:11, 2) plot(g) -g <- make_empty_graph(directed = FALSE, n = 10) \%>\% +g <- make_empty_graph(directed = FALSE, n = 10) |> set_vertex_attr("name", value = letters[1:10]) g2 <- g + path("a", "b", "c", "d") diff --git a/man/pipe.Rd b/man/pipe.Rd index 22008cb63f7..fe21e6c3bde 100644 --- a/man/pipe.Rd +++ b/man/pipe.Rd @@ -2,7 +2,10 @@ % Please edit documentation in R/igraph-package.R \name{\%>\%} \alias{\%>\%} -\title{Magrittr's pipes} +\title{Magrittr's pipe} +\usage{ +lhs \%>\% rhs +} \arguments{ \item{lhs}{Left hand side of the pipe.} @@ -13,12 +16,16 @@ Result of applying the right hand side to the result of the left hand side. } \description{ -igraph re-exports the \verb{\%>\%} operator of magrittr, because -we find it very useful. Please see the documentation in the -\code{magrittr} package. +\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} + +igraph used to re-export the \verb{\%>\%} operator of magrittr. Now that R has its +own base pipe, \verb{|>}, available since R 4.1.0, please use that instead. If +you still need \verb{\%>\%} and its extra features (such as the \code{.} placeholder), +import it from the \code{magrittr} package yourself. } \examples{ -make_ring(10) \%>\% - add_edges(c(1, 6)) \%>\% +make_ring(10) |> + add_edges(c(1, 6)) |> plot() } +\keyword{internal} diff --git a/man/print.igraph.es.Rd b/man/print.igraph.es.Rd index 5d3a9505ca2..2ea13f10de2 100644 --- a/man/print.igraph.es.Rd +++ b/man/print.igraph.es.Rd @@ -40,19 +40,19 @@ g <- make_ring(10) E(g) # Named graphs -g2 <- make_ring(10) \%>\% +g2 <- make_ring(10) |> set_vertex_attr("name", value = LETTERS[1:10]) E(g2) # All edges in a long sequence g3 <- make_ring(200) E(g3) -E(g3) \%>\% print(full = TRUE) +E(g3) |> print(full = TRUE) # Metadata -g4 <- make_ring(10) \%>\% - set_vertex_attr("name", value = LETTERS[1:10]) \%>\% - set_edge_attr("weight", value = 1:10) \%>\% +g4 <- make_ring(10) |> + set_vertex_attr("name", value = LETTERS[1:10]) |> + set_edge_attr("weight", value = 1:10) |> set_edge_attr("color", value = "green") E(g4) E(g4)[[]] diff --git a/man/print.igraph.vs.Rd b/man/print.igraph.vs.Rd index 92504a5dcd2..05f046cb413 100644 --- a/man/print.igraph.vs.Rd +++ b/man/print.igraph.vs.Rd @@ -40,7 +40,7 @@ g <- make_ring(10) V(g) # Named graphs -g2 <- make_ring(10) \%>\% +g2 <- make_ring(10) |> set_vertex_attr("name", value = LETTERS[1:10]) V(g2) @@ -50,8 +50,8 @@ V(g3) print(V(g3), full = TRUE) # Metadata -g4 <- make_ring(10) \%>\% - set_vertex_attr("name", value = LETTERS[1:10]) \%>\% +g4 <- make_ring(10) |> + set_vertex_attr("name", value = LETTERS[1:10]) |> set_vertex_attr("color", value = "red") V(g4)[[]] V(g4)[[2:5, 7:8]] diff --git a/man/rev.igraph.es.Rd b/man/rev.igraph.es.Rd index 8340875aa7c..8994f017481 100644 --- a/man/rev.igraph.es.Rd +++ b/man/rev.igraph.es.Rd @@ -18,7 +18,7 @@ Reverse the order in an edge sequence \examples{ g <- make_(ring(10), with_vertex_(name = LETTERS[1:10])) E(g) -E(g) \%>\% rev() +E(g) |> rev() } \seealso{ Other vertex and edge sequence operations: diff --git a/man/rev.igraph.vs.Rd b/man/rev.igraph.vs.Rd index 4bf1b654d9a..8c83e83ba0e 100644 --- a/man/rev.igraph.vs.Rd +++ b/man/rev.igraph.vs.Rd @@ -17,7 +17,7 @@ Reverse the order in a vertex sequence } \examples{ g <- make_(ring(10), with_vertex_(name = LETTERS[1:10])) -V(g) \%>\% rev() +V(g) |> rev() } \seealso{ Other vertex and edge sequence operations: diff --git a/man/rewire.Rd b/man/rewire.Rd index 773aa11d694..67965505a37 100644 --- a/man/rewire.Rd +++ b/man/rewire.Rd @@ -20,8 +20,8 @@ See the links below for the implemented rewiring methods. } \examples{ g <- make_ring(10) -g \%>\% - rewire(each_edge(p = 0.1, loops = FALSE)) \%>\% +g |> + rewire(each_edge(p = 0.1, loops = FALSE)) |> plot(layout = layout_in_circle) print_all(rewire(g, with = keeping_degseq(niter = vcount(g) * 10))) } diff --git a/man/sample_.Rd b/man/sample_.Rd index c4de74036ef..b2f7338286d 100644 --- a/man/sample_.Rd +++ b/man/sample_.Rd @@ -41,7 +41,7 @@ blocky <- sample_(sbm( block.sizes = c(10, 10) )) -blocky2 <- pref_matrix \%>\% +blocky2 <- pref_matrix |> sample_sbm(n = 20, block.sizes = c(10, 10)) } \seealso{ diff --git a/man/scan_stat.Rd b/man/scan_stat.Rd index 2a6a45e84be..54d31a87286 100644 --- a/man/scan_stat.Rd +++ b/man/scan_stat.Rd @@ -60,8 +60,8 @@ PA <- P0 PA[3, 3] <- p_ij$q num_v <- sum(block_sizes) -tsg <- replicate(num_t - 1, P0, simplify = FALSE) \%>\% - append(list(PA)) \%>\% +tsg <- replicate(num_t - 1, P0, simplify = FALSE) |> + append(list(PA)) |> lapply(sample_sbm, n = num_v, block.sizes = block_sizes, directed = TRUE) scan_stat(graphs = tsg, k = 1, tau = 4, ell = 2) diff --git a/man/sequential_pal.Rd b/man/sequential_pal.Rd index 34a28ada687..3934164d328 100644 --- a/man/sequential_pal.Rd +++ b/man/sequential_pal.Rd @@ -26,11 +26,11 @@ people, or their seniority level. \dontshow{if (rlang::is_installed(c("igraphdata", "scales"))) withAutoprint(\{ # examplesIf} library(igraphdata) data(karate) -karate <- karate \%>\% - add_layout_(with_kk()) \%>\% +karate <- karate |> + add_layout_(with_kk()) |> set_vertex_attr("size", value = 10) -V(karate)$color <- scales::dscale(degree(karate) \%>\% cut(5), sequential_pal) +V(karate)$color <- scales::dscale(degree(karate) |> cut(5), sequential_pal) plot(karate) \dontshow{\}) # examplesIf} } diff --git a/man/set_edge_attr.Rd b/man/set_edge_attr.Rd index ab5dd24576d..13792c601b3 100644 --- a/man/set_edge_attr.Rd +++ b/man/set_edge_attr.Rd @@ -29,7 +29,7 @@ Set edge attributes } \examples{ -g <- make_ring(10) \%>\% +g <- make_ring(10) |> set_edge_attr("label", value = LETTERS[1:10]) g plot(g) diff --git a/man/set_graph_attr.Rd b/man/set_graph_attr.Rd index 39d91cff5d7..e252e0ff701 100644 --- a/man/set_graph_attr.Rd +++ b/man/set_graph_attr.Rd @@ -20,7 +20,7 @@ The graph with the new graph attribute added or set. An existing attribute with the same name is overwritten. } \examples{ -g <- make_ring(10) \%>\% +g <- make_ring(10) |> set_graph_attr("layout", layout_with_fr) g plot(g) diff --git a/man/set_vertex_attr.Rd b/man/set_vertex_attr.Rd index 5d315ad020e..4f98c4ae3e1 100644 --- a/man/set_vertex_attr.Rd +++ b/man/set_vertex_attr.Rd @@ -29,7 +29,7 @@ Set vertex attributes } \examples{ -g <- make_ring(10) \%>\% +g <- make_ring(10) |> set_vertex_attr("label", value = LETTERS[1:10]) g plot(g) diff --git a/man/unique.igraph.es.Rd b/man/unique.igraph.es.Rd index dcbe287fa8b..c965b55474c 100644 --- a/man/unique.igraph.es.Rd +++ b/man/unique.igraph.es.Rd @@ -23,7 +23,7 @@ Remove duplicate edges from an edge sequence \examples{ g <- make_(ring(10), with_vertex_(name = LETTERS[1:10])) E(g)[1, 1:5, 1:10, 5:10] -E(g)[1, 1:5, 1:10, 5:10] \%>\% unique() +E(g)[1, 1:5, 1:10, 5:10] |> unique() } \seealso{ Other vertex and edge sequence operations: diff --git a/man/unique.igraph.vs.Rd b/man/unique.igraph.vs.Rd index 86b096745c4..b561c0ed1cf 100644 --- a/man/unique.igraph.vs.Rd +++ b/man/unique.igraph.vs.Rd @@ -23,7 +23,7 @@ Remove duplicate vertices from a vertex sequence \examples{ g <- make_(ring(10), with_vertex_(name = LETTERS[1:10])) V(g)[1, 1:5, 1:10, 5:10] -V(g)[1, 1:5, 1:10, 5:10] \%>\% unique() +V(g)[1, 1:5, 1:10, 5:10] |> unique() } \seealso{ Other vertex and edge sequence operations: diff --git a/man/vertex_attr.Rd b/man/vertex_attr.Rd index 5a864092fef..796844f4ccf 100644 --- a/man/vertex_attr.Rd +++ b/man/vertex_attr.Rd @@ -28,8 +28,8 @@ Query vertex attributes of a graph } \examples{ -g <- make_ring(10) \%>\% - set_vertex_attr("color", value = "red") \%>\% +g <- make_ring(10) |> + set_vertex_attr("color", value = "red") |> set_vertex_attr("label", value = letters[1:10]) vertex_attr(g, "label") vertex_attr(g) diff --git a/man/vertex_attr_names.Rd b/man/vertex_attr_names.Rd index 5ab35babb5b..4f4b36f64cc 100644 --- a/man/vertex_attr_names.Rd +++ b/man/vertex_attr_names.Rd @@ -16,8 +16,8 @@ Character vector, the names of the vertex attributes. List names of vertex attributes } \examples{ -g <- make_ring(10) \%>\% - set_vertex_attr("name", value = LETTERS[1:10]) \%>\% +g <- make_ring(10) |> + set_vertex_attr("name", value = LETTERS[1:10]) |> set_vertex_attr("color", value = rep("green", 10)) vertex_attr_names(g) plot(g) diff --git a/man/with_edge_.Rd b/man/with_edge_.Rd index 650cd360871..e71c4a0f401 100644 --- a/man/with_edge_.Rd +++ b/man/with_edge_.Rd @@ -19,7 +19,7 @@ make_( color = "red", weight = rep(1:2, 5) ) -) \%>\% +) |> plot() } \seealso{ diff --git a/man/with_vertex_.Rd b/man/with_vertex_.Rd index e1b6d04fc06..5883c1e1bcd 100644 --- a/man/with_vertex_.Rd +++ b/man/with_vertex_.Rd @@ -20,7 +20,7 @@ make_( frame.color = "#7fcdbb", name = LETTERS[1:10] ) -) \%>\% +) |> plot() } \seealso{ diff --git a/tests/testthat/test-attributes.R b/tests/testthat/test-attributes.R index f46f03db367..4c05c7b72f9 100644 --- a/tests/testthat/test-attributes.R +++ b/tests/testthat/test-attributes.R @@ -358,10 +358,10 @@ test_that("handle_vertex_type_arg validates and converts the type attribute", { test_that("without_attr", { igraph_local_seed(42) - g_stripped <- sample_gnp(10, 2 / 10) %>% - delete_graph_attr("name") %>% - delete_graph_attr("type") %>% - delete_graph_attr("loops") %>% + g_stripped <- sample_gnp(10, 2 / 10) |> + delete_graph_attr("name") |> + delete_graph_attr("type") |> + delete_graph_attr("loops") |> delete_graph_attr("p") igraph_local_seed(42) @@ -375,7 +375,7 @@ test_that("without_attr", { test_that("without_loops", { - g1 <- make_graph(~ A - A:B:C, B - A:B:C, simplify = FALSE) %>% + g1 <- make_graph(~ A - A:B:C, B - A:B:C, simplify = FALSE) |> simplify(remove.multiple = FALSE) g2 <- make_( @@ -389,7 +389,7 @@ test_that("without_loops", { test_that("without_multiple", { - g1 <- make_graph(~ A - A:B:C, B - A:B:C, simplify = FALSE) %>% + g1 <- make_graph(~ A - A:B:C, B - A:B:C, simplify = FALSE) |> simplify(remove.loops = FALSE) g2 <- make_( @@ -417,8 +417,8 @@ test_that("simplified", { test_that("with_vertex_", { - g1 <- make_graph(~ A - A:B:C, B - A:B:C) %>% - set_vertex_attr("color", value = "red") %>% + g1 <- make_graph(~ A - A:B:C, B - A:B:C) |> + set_vertex_attr("color", value = "red") |> set_vertex_attr("foo", value = paste0("xx", 1:3)) g2 <- make_( @@ -441,8 +441,8 @@ test_that("with_vertex_", { test_that("with_edge_", { - g1 <- make_graph(~ A - A:B:C, B - A:B:C) %>% - set_edge_attr("color", value = "red") %>% + g1 <- make_graph(~ A - A:B:C, B - A:B:C) |> + set_edge_attr("color", value = "red") |> set_edge_attr("foo", value = seq_len(3)) g2 <- make_( @@ -490,8 +490,8 @@ test_that("with_vertex_() / with_edge_() coerce igraph.vs / igraph.es to numeric test_that("with_graph_", { - g1 <- make_graph(~ A - A:B:C, B - A:B:C) %>% - set_graph_attr("color", value = "red") %>% + g1 <- make_graph(~ A - A:B:C, B - A:B:C) |> + set_graph_attr("color", value = "red") |> set_graph_attr("foo", value = 1:5) g2 <- make_( diff --git a/tests/testthat/test-cliques.R b/tests/testthat/test-cliques.R index 9d14e3d84a2..d59af115e63 100644 --- a/tests/testthat/test-cliques.R +++ b/tests/testthat/test-cliques.R @@ -246,9 +246,9 @@ test_that("ivs() works, cliques of complement", { # that the independent vertex sets of G are # the same as the cliques of the complement of G (and vice versa) gnp <- sample_gnp(50, 0.8) - ivs <- ivs(gnp, min = ivs_size(gnp)) %>% lapply(as.numeric) + ivs <- ivs(gnp, min = ivs_size(gnp)) |> lapply(as.numeric) complement <- complementer(gnp) - cliques <- cliques(complement, min = ivs_size(gnp)) %>% lapply(as.numeric) + cliques <- cliques(complement, min = ivs_size(gnp)) |> lapply(as.numeric) expect_equal(length(ivs), length(cliques)) diff --git a/tests/testthat/test-incidence.R b/tests/testthat/test-incidence.R index 90646d23f5d..244c21017ae 100644 --- a/tests/testthat/test-incidence.R +++ b/tests/testthat/test-incidence.R @@ -37,18 +37,18 @@ test_that("graph_from_biadjacency_matrix() works - dense, modes", { out_g <- graph_from_biadjacency_matrix(inc, directed = TRUE, mode = "out") expect_true(is_directed(out_g)) expect_length(E(out_g), 7) - expect_equal(as_adj_list(out_g, mode = "out")$A %>% as.numeric(), c(6, 7)) + expect_equal(as_adj_list(out_g, mode = "out")$A |> as.numeric(), c(6, 7)) in_g <- graph_from_biadjacency_matrix(inc, directed = TRUE, mode = "in") expect_true(is_directed(in_g)) expect_length(E(in_g), 7) - expect_equal(as_adj_list(in_g, mode = "in")$A %>% as.numeric(), c(6, 7)) + expect_equal(as_adj_list(in_g, mode = "in")$A |> as.numeric(), c(6, 7)) mutual_g <- graph_from_biadjacency_matrix(inc, directed = TRUE, mode = "all") expect_true(is_directed(mutual_g)) expect_length(E(mutual_g), 14) expect_equal( - as_adj_list(mutual_g, mode = "all")$A %>% as.numeric(), + as_adj_list(mutual_g, mode = "all")$A |> as.numeric(), c(6, 6, 7, 7) ) }) @@ -68,7 +68,7 @@ test_that("graph_from_biadjacency_matrix() works - dense, modes, weighted", { ) expect_true(is_directed(out_g)) expect_length(E(out_g), 8) - expect_equal(as_adj_list(out_g, mode = "out")$A %>% as.numeric(), c(6, 7, 8)) + expect_equal(as_adj_list(out_g, mode = "out")$A |> as.numeric(), c(6, 7, 8)) in_g <- graph_from_biadjacency_matrix( inc, @@ -78,7 +78,7 @@ test_that("graph_from_biadjacency_matrix() works - dense, modes, weighted", { ) expect_true(is_directed(in_g)) expect_length(E(in_g), 8) - expect_equal(as_adj_list(in_g, mode = "in")$A %>% as.numeric(), c(6, 7, 8)) + expect_equal(as_adj_list(in_g, mode = "in")$A |> as.numeric(), c(6, 7, 8)) mutual_g <- graph_from_biadjacency_matrix( inc, @@ -89,7 +89,7 @@ test_that("graph_from_biadjacency_matrix() works - dense, modes, weighted", { expect_true(is_directed(mutual_g)) expect_length(E(mutual_g), 16) expect_equal( - as_adj_list(mutual_g, mode = "all")$A %>% as.numeric(), + as_adj_list(mutual_g, mode = "all")$A |> as.numeric(), c(6, 6, 7, 7, 8, 8) ) @@ -145,18 +145,18 @@ test_that("graph_from_biadjacency_matrix() works - sparse, modes", { out_g <- graph_from_biadjacency_matrix(inc, directed = TRUE, mode = "out") expect_true(is_directed(out_g)) expect_length(E(out_g), 7) - expect_equal(as_adj_list(out_g, mode = "out")$A %>% as.numeric(), c(6, 7)) + expect_equal(as_adj_list(out_g, mode = "out")$A |> as.numeric(), c(6, 7)) in_g <- graph_from_biadjacency_matrix(inc, directed = TRUE, mode = "in") expect_true(is_directed(in_g)) expect_length(E(in_g), 7) - expect_equal(as_adj_list(in_g, mode = "in")$A %>% as.numeric(), c(6, 7)) + expect_equal(as_adj_list(in_g, mode = "in")$A |> as.numeric(), c(6, 7)) mutual_g <- graph_from_biadjacency_matrix(inc, directed = TRUE, mode = "all") expect_true(is_directed(mutual_g)) expect_length(E(mutual_g), 14) expect_equal( - as_adj_list(mutual_g, mode = "all")$A %>% as.numeric(), + as_adj_list(mutual_g, mode = "all")$A |> as.numeric(), c(6, 6, 7, 7) ) }) @@ -177,7 +177,7 @@ test_that("graph_from_biadjacency_matrix() works - sparse, modes, weighted", { ) expect_true(is_directed(out_g)) expect_length(E(out_g), 8) - expect_equal(as_adj_list(out_g, mode = "out")$A %>% as.numeric(), c(6, 7, 8)) + expect_equal(as_adj_list(out_g, mode = "out")$A |> as.numeric(), c(6, 7, 8)) in_g <- graph_from_biadjacency_matrix( inc, @@ -187,7 +187,7 @@ test_that("graph_from_biadjacency_matrix() works - sparse, modes, weighted", { ) expect_true(is_directed(in_g)) expect_length(E(in_g), 8) - expect_equal(as_adj_list(in_g, mode = "in")$A %>% as.numeric(), c(6, 7, 8)) + expect_equal(as_adj_list(in_g, mode = "in")$A |> as.numeric(), c(6, 7, 8)) mutual_g <- graph_from_biadjacency_matrix( inc, @@ -198,7 +198,7 @@ test_that("graph_from_biadjacency_matrix() works - sparse, modes, weighted", { expect_true(is_directed(mutual_g)) expect_length(E(mutual_g), 16) expect_equal( - as_adj_list(mutual_g, mode = "all")$A %>% as.numeric(), + as_adj_list(mutual_g, mode = "all")$A |> as.numeric(), c(6, 6, 7, 7, 8, 8) ) }) diff --git a/tests/testthat/test-layout.R b/tests/testthat/test-layout.R index 0c65aef7c1d..e781f0d7d21 100644 --- a/tests/testthat/test-layout.R +++ b/tests/testthat/test-layout.R @@ -318,7 +318,7 @@ test_that("parameters are evaluated early", { test_that("piping form is OK, too", { g <- make_ring(10) l1 <- layout_as_star(g, center = 5) - l2 <- g %>% + l2 <- g |> layout_(as_star(center = 5)) expect_identical(l1, l2) }) @@ -329,8 +329,8 @@ test_that("add_layout_ works", { l2 <- add_layout_(g, as_star(center = 5))$layout expect_identical(l1, l2) - l3 <- g %>% - add_layout_(as_star(center = 5)) %>% + l3 <- g |> + add_layout_(as_star(center = 5)) |> graph_attr("layout") expect_identical(l1, l3) }) diff --git a/tests/testthat/test-print-classic.R b/tests/testthat/test-print-classic.R index b488622800c..8c96049899f 100644 --- a/tests/testthat/test-print-classic.R +++ b/tests/testthat/test-print-classic.R @@ -138,8 +138,8 @@ test_that("classic: print.igraph.es() uses vertex names", { test_that("classic: vs printing", { igraph_local_seed(42, rng_version = "3.5.0") - g <- make_graph(~ A - A:B:C, B - A:B:C) %>% - set_vertex_attr("color", value = "red") %>% + g <- make_graph(~ A - A:B:C, B - A:B:C) |> + set_vertex_attr("color", value = "red") |> set_vertex_attr("weight", value = sample(1:10, 3)) expect_snapshot({ @@ -152,9 +152,9 @@ test_that("classic: vs printing", { test_that("classic: vs printing, complex attributes", { igraph_local_seed(42, rng_version = "3.5.0") - g <- make_graph(~ A - A:B:C, B - A:B:C) %>% - set_vertex_attr("color", value = "red") %>% - set_vertex_attr("weight", value = sample(1:10, 3)) %>% + g <- make_graph(~ A - A:B:C, B - A:B:C) |> + set_vertex_attr("color", value = "red") |> + set_vertex_attr("weight", value = sample(1:10, 3)) |> set_vertex_attr("cplx", value = replicate(3, 1:4, simplify = FALSE)) expect_snapshot({ @@ -165,8 +165,8 @@ test_that("classic: vs printing, complex attributes", { test_that("classic: es printing", { igraph_local_seed(42, rng_version = "3.5.0") - g <- make_graph(~ A - A:B:C, B - A:B:C) %>% - set_edge_attr("color", value = "red") %>% + g <- make_graph(~ A - A:B:C, B - A:B:C) |> + set_edge_attr("color", value = "red") |> set_edge_attr("weight", value = sample(1:10, 3)) expect_snapshot({ @@ -177,9 +177,9 @@ test_that("classic: es printing", { test_that("classic: es printing, complex attributes", { igraph_local_seed(42, rng_version = "3.5.0") - g <- make_graph(~ A - A:B:C, B - A:B:C) %>% - set_edge_attr("color", value = "red") %>% - set_edge_attr("weight", value = sample(1:10, 3)) %>% + g <- make_graph(~ A - A:B:C, B - A:B:C) |> + set_edge_attr("color", value = "red") |> + set_edge_attr("weight", value = sample(1:10, 3)) |> set_edge_attr("cmpx", value = replicate(3, 1:4, simplify = FALSE)) expect_snapshot({ diff --git a/tests/testthat/test-rewire.R b/tests/testthat/test-rewire.R index 4382025e8ce..4aa741e7a6f 100644 --- a/tests/testthat/test-rewire.R +++ b/tests/testthat/test-rewire.R @@ -2,7 +2,7 @@ test_that("rewire(each_edge(mode='in')) keeps the in-degree distribution", { igraph_local_seed(42) g <- sample_pa(1000) - g2 <- g %>% rewire(each_edge(mode = "in", multiple = T, prob = 0.2)) + g2 <- g |> rewire(each_edge(mode = "in", multiple = T, prob = 0.2)) expect_equal(degree(g, mode = "in"), degree(g2, mode = "in")) expect_false(all(degree(g, mode = "out") == degree(g2, mode = "out"))) }) @@ -11,7 +11,7 @@ test_that("rewire(each_edge(mode='out')) keeps the out-degree distribution", { igraph_local_seed(42) g <- sample_pa(1000) - g2 <- g %>% rewire(each_edge(mode = "out", multiple = T, prob = 0.2)) + g2 <- g |> rewire(each_edge(mode = "out", multiple = T, prob = 0.2)) expect_equal(degree(g, mode = "out"), degree(g2, mode = "out")) expect_false(all(degree(g, mode = "in") == degree(g2, mode = "in"))) }) @@ -19,7 +19,7 @@ test_that("rewire(each_edge(mode='out')) keeps the out-degree distribution", { test_that("rewire() with zero probability does not do anything", { igraph_local_seed(42) g <- sample_pa(100) - g2 <- g %>% rewire(each_edge(prob = 0)) + g2 <- g |> rewire(each_edge(prob = 0)) expect_identical_graphs(g, g2) }) @@ -29,7 +29,7 @@ test_that("each_edge() takes all tail arguments by name", { igraph_local_seed(42) g <- sample_pa(100) - g2 <- g %>% + g2 <- g |> rewire(each_edge(prob = 1, loops = TRUE, multiple = TRUE, mode = "out")) # Rewiring only the heads keeps the out-degree sequence and the edge count. expect_equal(degree(g2, mode = "out"), degree(g, mode = "out")) diff --git a/vignettes/igraph.Rmd b/vignettes/igraph.Rmd index 6682bc6b3fc..e436f983155 100644 --- a/vignettes/igraph.Rmd +++ b/vignettes/igraph.Rmd @@ -133,12 +133,12 @@ If you try to add edges to vertices with invalid IDs (i.e., you try to add an ed g <- add_edges(g, edges = c(38, 37)) ``` -Let us add some more vertices and edges to our graph. In `igraph` we can use the `magrittr` package, which provides a mechanism for chaining commands with the operator `%>%`: +Let us add some more vertices and edges to our graph. In `igraph` we can use R's base pipe operator, `|>`, to chain commands: ```{r echo = TRUE} -g <- g %>% - add_edges(edges = c(1, 34)) %>% - add_vertices(3) %>% +g <- g |> + add_edges(edges = c(1, 34)) |> + add_vertices(3) |> add_edges(edges = c(38, 39, 39, 40, 40, 38, 40, 37)) g ``` @@ -157,7 +157,7 @@ g <- delete_edges(g, edge_id_to_delete) As an example, to create a broken ring: ```{r echo = TRUE} -g <- make_ring(10) %>% delete_edges("10|1") +g <- make_ring(10) |> delete_edges("10|1") plot(g) ``` @@ -261,15 +261,15 @@ E(g)$is_formal <- c(FALSE, FALSE, TRUE, TRUE, TRUE, FALSE, TRUE, FALSE, FALSE) summary(g) ``` -`V()` and `E()` are the standard way to obtain a sequence of all vertices and edges, respectively. This assigns an attribute to *all* vertices/edges at once. Another way to generate our social network is with the use of `set_vertex_attr()` and `set_edge_attr()` and the operator `%>%`: +`V()` and `E()` are the standard way to obtain a sequence of all vertices and edges, respectively. This assigns an attribute to *all* vertices/edges at once. Another way to generate our social network is with the use of `set_vertex_attr()` and `set_edge_attr()` and the operator `|>`: ```{r echo = TRUE, eval=FALSE} g <- make_graph( ~ Alice - Boris:Himari:Moshe, Himari - Alice:Nang:Moshe:Samira, Ibrahim - Nang:Moshe, Nang - Samira -) %>% - set_vertex_attr("age", value = c(25, 31, 18, 23, 47, 22, 50)) %>% - set_vertex_attr("gender", value = c("f", "m", "f", "m", "m", "f", "m")) %>% +) |> + set_vertex_attr("age", value = c(25, 31, 18, 23, 47, 22, 50)) |> + set_vertex_attr("gender", value = c("f", "m", "f", "m", "m", "f", "m")) |> set_edge_attr("is_formal", value = c(FALSE, FALSE, TRUE, TRUE, TRUE, FALSE, TRUE, FALSE, FALSE)) summary(g) ``` diff --git a/vignettes/igraph_ES.rmd b/vignettes/igraph_ES.rmd index c102c204450..56fa143813f 100644 --- a/vignettes/igraph_ES.rmd +++ b/vignettes/igraph_ES.rmd @@ -140,12 +140,12 @@ Si intentas añadir aristas a vértices con IDs no válidos (por ejemplo, intent g <- add_edges(g, edges = c(38, 37)) ``` -Añadamos más vértices y aristas a nuestro grafo. En `igraph` podemos utilizar el paquete `magrittr`, que proporciona un mecanismo para encadenar comandos con el operador `%>%`: +Añadamos más vértices y aristas a nuestro grafo. En `igraph` podemos utilizar el operador de tubería (`pipe`) base de R, `|>`, para encadenar comandos: ```{r echo = TRUE} -g <- g %>% - add_edges(edges = c(1, 34)) %>% - add_vertices(3) %>% +g <- g |> + add_edges(edges = c(1, 34)) |> + add_vertices(3) |> add_edges(edges = c(38, 39, 39, 40, 40, 38, 40, 37)) g ``` @@ -164,7 +164,7 @@ g <- delete_edges(g, edge_id_para_borrar) Por ejemplo, para crear un grafo con forma de anillo y para partirlo: ```{r echo = TRUE} -g <- make_ring(10) %>% delete_edges("10|1") +g <- make_ring(10) |> delete_edges("10|1") plot(g) ``` @@ -271,7 +271,7 @@ E(g)$is_formal <- c(FALSE, FALSE, TRUE, TRUE, TRUE, FALSE, TRUE, FALSE, FALSE) summary(g) ``` -`V` y `E` son la forma estándar de obtener una secuencia de todos los vértices y aristas respectivamente. Esto asigna un atributo a *todos* los vértices/aristas a la vez. Otra forma de generar nuestra red social es con el uso de `set_vertex_attr()` y `set_edge_attr()` y el operador `%>%`: +`V` y `E` son la forma estándar de obtener una secuencia de todos los vértices y aristas respectivamente. Esto asigna un atributo a *todos* los vértices/aristas a la vez. Otra forma de generar nuestra red social es con el uso de `set_vertex_attr()` y `set_edge_attr()` y el operador `|>`: ```{r echo = TRUE, eval=FALSE} g <- make_graph( @@ -279,9 +279,9 @@ g <- make_graph( Himari-Alice:Nang:Moshe:Samira, Ibrahim-Nang:Moshe, Nang-Samira -) %>% - set_vertex_attr("age", value = c(25, 31, 18, 23, 47, 22, 50)) %>% - set_vertex_attr("gender", value = c("f", "m", "f", "m", "m", "f", "m")) %>% +) |> + set_vertex_attr("age", value = c(25, 31, 18, 23, 47, 22, 50)) |> + set_vertex_attr("gender", value = c("f", "m", "f", "m", "m", "f", "m")) |> set_edge_attr("is_formal", value = c(FALSE, FALSE, TRUE, TRUE, TRUE, FALSE, TRUE, FALSE, FALSE)) summary(g) ```