diff --git a/R/basic.R b/R/basic.R index 4769854df3..74bdb69bef 100644 --- a/R/basic.R +++ b/R/basic.R @@ -63,14 +63,26 @@ is_igraph <- function(graph) { #' `tail_of()` returns the other end(s) of the edge(s). #' #' @param graph The input graph. -#' @param es The edges to query. +#' @param edges The edges to query. +#' @param es `r lifecycle::badge("deprecated")` Use `edges` instead. #' @return A vertex sequence with the head(s) of the edge(s). #' #' @family structural queries #' #' @export -head_of <- function(graph, es) { - create_vs(graph, ends(graph, es, names = FALSE)[, 2]) +head_of <- function(graph, edges, es = deprecated()) { + if (lifecycle::is_present(es)) { + if (!missing(edges)) { + cli::cli_abort(c( + "Argument {.arg edges} of {.fn head_of} was supplied more than once.", + i = "It was also supplied via its legacy name {.arg es}." + )) + } + lifecycle::deprecate_soft("3.0.0", "head_of(es = )", "head_of(edges = )") + edges <- es + } + + create_vs(graph, ends(graph, edges, names = FALSE)[, 2]) } #' Tails of the edge(s) in a graph @@ -80,12 +92,24 @@ head_of <- function(graph, es) { #' `head_of()` returns the other end(s) of the edge(s). #' #' @param graph The input graph. -#' @param es The edges to query. +#' @param edges The edges to query. +#' @param es `r lifecycle::badge("deprecated")` Use `edges` instead. #' @return A vertex sequence with the tail(s) of the edge(s). #' #' @family structural queries #' #' @export -tail_of <- function(graph, es) { - create_vs(graph, ends(graph, es, names = FALSE)[, 1]) +tail_of <- function(graph, edges, es = deprecated()) { + if (lifecycle::is_present(es)) { + if (!missing(edges)) { + cli::cli_abort(c( + "Argument {.arg edges} of {.fn tail_of} was supplied more than once.", + i = "It was also supplied via its legacy name {.arg es}." + )) + } + lifecycle::deprecate_soft("3.0.0", "tail_of(es = )", "tail_of(edges = )") + edges <- es + } + + create_vs(graph, ends(graph, edges, names = FALSE)[, 1]) } diff --git a/R/centrality.R b/R/centrality.R index 51300d7500..6a626c8139 100644 --- a/R/centrality.R +++ b/R/centrality.R @@ -415,7 +415,7 @@ betweenness.estimate <- estimate_betweenness #' @return A numeric vector with the betweenness score for each vertex in #' `vertices` for `betweenness()`. #' -#' A numeric vector with the edge betweenness score for each edge in `e` +#' A numeric vector with the edge betweenness score for each edge in `edges` #' for `edge_betweenness()`. #' #' @note `edge_betweenness()` might give false values for graphs with @@ -559,21 +559,64 @@ betweenness <- function( } #' @rdname betweenness -#' @param e The edges for which the edge betweenness will be calculated. +#' @param edges The edges for which the edge betweenness will be calculated. #' The default `NULL` selects all edges. +#' @param e `r lifecycle::badge("deprecated")` Use `edges` instead. #' @inheritParams rlang::args_dots_empty #' @export edge_betweenness <- function( graph, - e = NULL, + edges = NULL, ..., directed = TRUE, weights = NULL, - cutoff = -1 + cutoff = -1, + e = deprecated() ) { # BEGIN GENERATED ARG_HANDLE: edge_betweenness, do not edit, see tools/generate-migrations.R # fmt: skip - if (...length() > 0L) { + if (!base::missing(e)) { + # Pre-3.0.0 signature: edge_betweenness(graph, e, directed, weights, cutoff) + .legacy_signature <- function(graph, e, directed, weights, cutoff, ...) { + base::list(env = base::environment(), n_extra = ...length(), extra = base::as.character(base::names(base::substitute(...()))), recovered = base::c( + if (!base::missing(graph)) base::c(graph = "graph"), + if (!base::missing(e)) base::c(edges = "e"), + if (!base::missing(directed)) base::c(directed = "directed"), + if (!base::missing(weights)) base::c(weights = "weights"), + if (!base::missing(cutoff)) base::c(cutoff = "cutoff") + )) + } + .arg_call <- base::sys.call() + .arg_call[[1L]] <- .legacy_signature + .arg_handle <- base::eval(.arg_call, base::parent.frame()) + .arg_extra <- .arg_handle$extra + if (.arg_handle$n_extra > base::sum(base::nzchar(.arg_extra))) cli::cli_abort("Too many arguments passed to {.fn edge_betweenness}.") + .arg_explicit <- base::c("graph", "edges", "directed", "weights", "cutoff", "e")[base::pmatch(.arg_extra, base::c("graph", "edges", "directed", "weights", "cutoff", "e"), duplicates.ok = TRUE)] + if (base::anyNA(.arg_explicit)) cli::cli_abort("Unexpected argument passed to {.fn edge_betweenness}: {.arg {(.arg_extra[base::is.na(.arg_explicit)])}}.") + .arg_recovered <- .arg_handle$recovered + .arg_names <- base::names(.arg_recovered) + .arg_conflict <- base::intersect(.arg_names, .arg_explicit) + if (base::length(.arg_conflict) > 0L) { + .arg_conflict <- .arg_conflict[[1L]] + .arg_via <- .arg_recovered[[.arg_conflict]] + cli::cli_abort(base::c("Argument {.arg {(.arg_conflict)}} of {.fn edge_betweenness} was supplied more than once.", i = if (base::is.element(.arg_via, base::names(.arg_call))) "It was also supplied via its legacy name {.arg {(.arg_via)}}." else "It was also passed by position, as {.arg {(.arg_via)}} of the old signature.")) + } + for (.arg_i in base::seq_along(.arg_recovered)) base::do.call(base::delayedAssign, base::list(.arg_names[[.arg_i]], base::call("[[", .arg_handle$env, .arg_recovered[[.arg_i]]), base::baseenv(), base::environment())) + if (!base::missing(e)) lifecycle::deprecate_soft("3.0.0", "edge_betweenness(e = )", "edge_betweenness(edges = )") + .arg_tail <- .arg_recovered[base::is.element(.arg_recovered, base::c("directed", "weights", "cutoff"))] + .arg_tail <- .arg_tail[!base::is.element(.arg_tail, base::names(.arg_call)) | base::names(.arg_tail) != .arg_tail] + if (base::length(.arg_tail) > 0L) { + .arg_shown <- base::ifelse(base::is.element(.arg_tail, base::names(.arg_call)), base::paste0(.arg_tail, " = "), .arg_tail) + lifecycle::deprecate_soft( + "3.0.0", + what = base::I("Calling `edge_betweenness()` with positional, abbreviated or renamed arguments"), + details = base::c( + i = base::paste0("Detected call: edge_betweenness(", base::paste(base::c("graph", "edges", .arg_shown), collapse = ", "), ")"), + i = base::paste0("Use instead: edge_betweenness(", base::paste(base::c("graph", "edges", base::paste0(base::names(.arg_tail), " = ")), collapse = ", "), ")") + ) + ) + } + } else if (...length() > 0L) { # Pre-3.0.0 signature: edge_betweenness(graph, e, directed, weights, cutoff) .old_signature <- function(directed, weights, cutoff, ...) { if (...length() > 0L) { @@ -607,26 +650,26 @@ edge_betweenness <- function( "3.0.0", what = base::I("Calling `edge_betweenness()` with positional or abbreviated arguments"), details = base::c( - i = base::paste0("Detected call: edge_betweenness(", base::paste(base::c("graph", "e", .arg_shown), collapse = ", "), ")"), - i = base::paste0("Use instead: edge_betweenness(", base::paste(base::c("graph", "e", base::paste0(.arg_names, " = ")), collapse = ", "), ")") + i = base::paste0("Detected call: edge_betweenness(", base::paste(base::c("graph", "edges", .arg_shown), collapse = ", "), ")"), + i = base::paste0("Use instead: edge_betweenness(", base::paste(base::c("graph", "edges", base::paste0(.arg_names, " = ")), collapse = ", "), ")") ) ) } } # END GENERATED ARG_HANDLE - if (is.null(e)) { - e <- E(graph) + if (is.null(edges)) { + edges <- E(graph) } - e <- as_igraph_es(graph, e) + edges <- as_igraph_es(graph, edges) res <- edge_betweenness_cutoff_impl( graph = graph, directed = directed, weights = weights, cutoff = cutoff ) - res[as.numeric(e)] + res[as.numeric(edges)] } #' Deprecated version of `edge_betweenness()` diff --git a/R/interface.R b/R/interface.R index 1561084ac2..2389c128b4 100644 --- a/R/interface.R +++ b/R/interface.R @@ -619,7 +619,8 @@ is_directed <- function(graph) { #' Incident vertices of some graph edges #' #' @param graph The input graph -#' @param es The sequence of edges to query +#' @param edges The sequence of edges to query +#' @param es `r lifecycle::badge("deprecated")` Use `edges` instead. #' @inheritParams rlang::args_dots_empty #' @param names Whether to return vertex names or #' numeric vertex IDs. By default vertex names are used. @@ -635,13 +636,55 @@ is_directed <- function(graph) { #' ends(g, E(g)) ends <- function( graph, - es, + edges, ..., - names = TRUE + names = TRUE, + es = deprecated() ) { # BEGIN GENERATED ARG_HANDLE: ends, do not edit, see tools/generate-migrations.R # fmt: skip - if (...length() > 0L) { + if (!base::missing(es)) { + # Pre-3.0.0 signature: ends(graph, es, names) + .legacy_signature <- function(graph, es, names, ...) { + base::list(env = base::environment(), n_extra = ...length(), extra = base::as.character(base::names(base::substitute(...()))), recovered = base::c( + if (!base::missing(graph)) base::c(graph = "graph"), + if (!base::missing(es)) base::c(edges = "es"), + if (!base::missing(names)) base::c(names = "names") + )) + } + .arg_call <- base::sys.call() + .arg_call[[1L]] <- .legacy_signature + .arg_handle <- base::eval(.arg_call, base::parent.frame()) + .arg_extra <- .arg_handle$extra + if (.arg_handle$n_extra > base::sum(base::nzchar(.arg_extra))) cli::cli_abort("Too many arguments passed to {.fn ends}.") + .arg_explicit <- base::c("graph", "edges", "names", "es")[base::pmatch(.arg_extra, base::c("graph", "edges", "names", "es"), duplicates.ok = TRUE)] + if (base::anyNA(.arg_explicit)) cli::cli_abort("Unexpected argument passed to {.fn ends}: {.arg {(.arg_extra[base::is.na(.arg_explicit)])}}.") + .arg_recovered <- .arg_handle$recovered + .arg_names <- base::names(.arg_recovered) + .arg_conflict <- base::intersect(.arg_names, .arg_explicit) + if (base::length(.arg_conflict) > 0L) { + .arg_conflict <- .arg_conflict[[1L]] + .arg_via <- .arg_recovered[[.arg_conflict]] + cli::cli_abort(base::c("Argument {.arg {(.arg_conflict)}} of {.fn ends} was supplied more than once.", i = if (base::is.element(.arg_via, base::names(.arg_call))) "It was also supplied via its legacy name {.arg {(.arg_via)}}." else "It was also passed by position, as {.arg {(.arg_via)}} of the old signature.")) + } + for (.arg_i in base::seq_along(.arg_recovered)) base::do.call(base::delayedAssign, base::list(.arg_names[[.arg_i]], base::call("[[", .arg_handle$env, .arg_recovered[[.arg_i]]), base::baseenv(), base::environment())) + if (!base::missing(es)) lifecycle::deprecate_soft("3.0.0", "ends(es = )", "ends(edges = )") + .arg_tail <- .arg_recovered[base::is.element(.arg_recovered, base::c("names"))] + .arg_tail <- .arg_tail[!base::is.element(.arg_tail, base::names(.arg_call)) | base::names(.arg_tail) != .arg_tail] + if (base::length(.arg_tail) > 0L) { + .arg_shown <- base::ifelse(base::is.element(.arg_tail, base::names(.arg_call)), base::paste0(.arg_tail, " = "), .arg_tail) + lifecycle::deprecate_soft( + "3.0.0", + what = base::I("Calling `ends()` with positional, abbreviated or renamed arguments"), + details = base::c( + i = base::paste0("Detected call: ends(", base::paste(base::c("graph", "edges", .arg_shown), collapse = ", "), ")"), + i = base::paste0("Use instead: ends(", base::paste(base::c("graph", "edges", base::paste0(base::names(.arg_tail), " = ")), collapse = ", "), ")") + ) + ) + } + } else if (...length() > 0L) { + .arg_forbidden <- base::intersect(base::names(base::sys.call()), base::c("e")) + if (base::length(.arg_forbidden) > 0L) cli::cli_abort(base::c("Argument {.arg {(.arg_forbidden)}} matches multiple formal arguments of {.fn ends}.", i = "Spell out the full argument name.")) # Pre-3.0.0 signature: ends(graph, es, names) .old_signature <- function(names, ...) { if (...length() > 0L) { @@ -671,8 +714,8 @@ ends <- function( "3.0.0", what = base::I("Calling `ends()` with positional or abbreviated arguments"), details = base::c( - i = base::paste0("Detected call: ends(", base::paste(base::c("graph", "es", .arg_shown), collapse = ", "), ")"), - i = base::paste0("Use instead: ends(", base::paste(base::c("graph", "es", base::paste0(.arg_names, " = ")), collapse = ", "), ")") + i = base::paste0("Detected call: ends(", base::paste(base::c("graph", "edges", .arg_shown), collapse = ", "), ")"), + i = base::paste0("Use instead: ends(", base::paste(base::c("graph", "edges", base::paste0(.arg_names, " = ")), collapse = ", "), ")") ) ) } @@ -681,14 +724,14 @@ ends <- function( ensure_igraph(graph) - res <- matrix(NA_integer_, ncol = length(es), nrow = 2) + res <- matrix(NA_integer_, ncol = length(edges), nrow = 2) - if (length(es) > 0) { + if (length(edges) > 0) { edge_data <- edges_impl( graph = graph, - eids = es + eids = edges ) - res[, !is.na(es)] <- edge_data + res[, !is.na(edges)] <- edge_data } if (names && is_named(graph)) { diff --git a/R/iterators.R b/R/iterators.R index c1c7806732..4c7c55abe6 100644 --- a/R/iterators.R +++ b/R/iterators.R @@ -680,7 +680,7 @@ E <- function( names(res) <- edge_attr(graph)$name[res] } if (is_named(graph)) { - el <- ends(graph, es = res) + el <- ends(graph, edges = res) attr(res, "vnames") <- paste(el[, 1], el[, 2], sep = "|") } diff --git a/R/operators.R b/R/operators.R index 37686bbcb8..791a3e4d81 100644 --- a/R/operators.R +++ b/R/operators.R @@ -1662,12 +1662,13 @@ rep.igraph <- function(x, n, mark = TRUE, ...) { #' #' The new graph will contain the same vertices, edges and attributes as #' the original graph, except that the direction of the edges selected by -#' their edge IDs in the `eids` argument will be reversed. When reversing +#' their edge IDs in the `edges` argument will be reversed. When reversing #' all edges, this operation is also known as graph transpose. #' #' @param graph The input graph. -#' @param eids The edge IDs of the edges to reverse. The default `NULL` +#' @param edges The edge IDs of the edges to reverse. The default `NULL` #' reverses all edges. +#' @param eids `r lifecycle::badge("deprecated")` Use `edges` instead. #' @return The result graph where the direction of the edges with the given #' IDs are reversed #' @@ -1677,14 +1678,29 @@ rep.igraph <- function(x, n, mark = TRUE, ...) { #' reverse_edges(g, 2) #' @family functions for manipulating graph structure #' @export -reverse_edges <- function(graph, eids = NULL) { - if (is.null(eids)) { - eids <- E(graph) +reverse_edges <- function(graph, edges = NULL, eids = deprecated()) { + if (lifecycle::is_present(eids)) { + if (!missing(edges)) { + cli::cli_abort(c( + "Argument {.arg edges} of {.fn reverse_edges} was supplied more than once.", + i = "It was also supplied via its legacy name {.arg eids}." + )) + } + lifecycle::deprecate_soft( + "3.0.0", + "reverse_edges(eids = )", + "reverse_edges(edges = )" + ) + edges <- eids + } + + if (is.null(edges)) { + edges <- E(graph) } reverse_edges_impl( graph = graph, - eids = eids + eids = edges ) } diff --git a/R/structural-properties.R b/R/structural-properties.R index 14d5a0f07f..15a0085a73 100644 --- a/R/structural-properties.R +++ b/R/structural-properties.R @@ -2312,20 +2312,63 @@ induced_subgraph <- function( } #' @rdname subgraph -#' @param eids The edge IDs of the edges that will be kept in the result graph. +#' @param edges The edge IDs of the edges that will be kept in the result graph. +#' @param eids `r lifecycle::badge("deprecated")` Use `edges` instead. #' @inheritParams rlang::args_dots_empty #' @param delete.vertices Logical, whether to remove vertices that do -#' not have any adjacent edges in `eids`. +#' not have any adjacent edges in `edges`. #' @export subgraph_from_edges <- function( graph, - eids, + edges, ..., - delete.vertices = TRUE + delete.vertices = TRUE, + eids = deprecated() ) { # BEGIN GENERATED ARG_HANDLE: subgraph_from_edges, do not edit, see tools/generate-migrations.R # fmt: skip - if (...length() > 0L) { + if (!base::missing(eids)) { + # Pre-3.0.0 signature: subgraph_from_edges(graph, eids, delete.vertices) + .legacy_signature <- function(graph, eids, delete.vertices, ...) { + base::list(env = base::environment(), n_extra = ...length(), extra = base::as.character(base::names(base::substitute(...()))), recovered = base::c( + if (!base::missing(graph)) base::c(graph = "graph"), + if (!base::missing(eids)) base::c(edges = "eids"), + if (!base::missing(delete.vertices)) base::c(delete.vertices = "delete.vertices") + )) + } + .arg_call <- base::sys.call() + .arg_call[[1L]] <- .legacy_signature + .arg_handle <- base::eval(.arg_call, base::parent.frame()) + .arg_extra <- .arg_handle$extra + if (.arg_handle$n_extra > base::sum(base::nzchar(.arg_extra))) cli::cli_abort("Too many arguments passed to {.fn subgraph_from_edges}.") + .arg_explicit <- base::c("graph", "edges", "delete.vertices", "eids")[base::pmatch(.arg_extra, base::c("graph", "edges", "delete.vertices", "eids"), duplicates.ok = TRUE)] + if (base::anyNA(.arg_explicit)) cli::cli_abort("Unexpected argument passed to {.fn subgraph_from_edges}: {.arg {(.arg_extra[base::is.na(.arg_explicit)])}}.") + .arg_recovered <- .arg_handle$recovered + .arg_names <- base::names(.arg_recovered) + .arg_conflict <- base::intersect(.arg_names, .arg_explicit) + if (base::length(.arg_conflict) > 0L) { + .arg_conflict <- .arg_conflict[[1L]] + .arg_via <- .arg_recovered[[.arg_conflict]] + cli::cli_abort(base::c("Argument {.arg {(.arg_conflict)}} of {.fn subgraph_from_edges} was supplied more than once.", i = if (base::is.element(.arg_via, base::names(.arg_call))) "It was also supplied via its legacy name {.arg {(.arg_via)}}." else "It was also passed by position, as {.arg {(.arg_via)}} of the old signature.")) + } + for (.arg_i in base::seq_along(.arg_recovered)) base::do.call(base::delayedAssign, base::list(.arg_names[[.arg_i]], base::call("[[", .arg_handle$env, .arg_recovered[[.arg_i]]), base::baseenv(), base::environment())) + if (!base::missing(eids)) lifecycle::deprecate_soft("3.0.0", "subgraph_from_edges(eids = )", "subgraph_from_edges(edges = )") + .arg_tail <- .arg_recovered[base::is.element(.arg_recovered, base::c("delete.vertices"))] + .arg_tail <- .arg_tail[!base::is.element(.arg_tail, base::names(.arg_call)) | base::names(.arg_tail) != .arg_tail] + if (base::length(.arg_tail) > 0L) { + .arg_shown <- base::ifelse(base::is.element(.arg_tail, base::names(.arg_call)), base::paste0(.arg_tail, " = "), .arg_tail) + lifecycle::deprecate_soft( + "3.0.0", + what = base::I("Calling `subgraph_from_edges()` with positional, abbreviated or renamed arguments"), + details = base::c( + i = base::paste0("Detected call: subgraph_from_edges(", base::paste(base::c("graph", "edges", .arg_shown), collapse = ", "), ")"), + i = base::paste0("Use instead: subgraph_from_edges(", base::paste(base::c("graph", "edges", base::paste0(base::names(.arg_tail), " = ")), collapse = ", "), ")") + ) + ) + } + } else if (...length() > 0L) { + .arg_forbidden <- base::intersect(base::names(base::sys.call()), base::c("e")) + if (base::length(.arg_forbidden) > 0L) cli::cli_abort(base::c("Argument {.arg {(.arg_forbidden)}} matches multiple formal arguments of {.fn subgraph_from_edges}.", i = "Spell out the full argument name.")) # Pre-3.0.0 signature: subgraph_from_edges(graph, eids, delete.vertices) .old_signature <- function(delete.vertices, ...) { if (...length() > 0L) { @@ -2355,8 +2398,8 @@ subgraph_from_edges <- function( "3.0.0", what = base::I("Calling `subgraph_from_edges()` with positional or abbreviated arguments"), details = base::c( - i = base::paste0("Detected call: subgraph_from_edges(", base::paste(base::c("graph", "eids", .arg_shown), collapse = ", "), ")"), - i = base::paste0("Use instead: subgraph_from_edges(", base::paste(base::c("graph", "eids", base::paste0(.arg_names, " = ")), collapse = ", "), ")") + i = base::paste0("Detected call: subgraph_from_edges(", base::paste(base::c("graph", "edges", .arg_shown), collapse = ", "), ")"), + i = base::paste0("Use instead: subgraph_from_edges(", base::paste(base::c("graph", "edges", base::paste0(.arg_names, " = ")), collapse = ", "), ")") ) ) } @@ -2366,13 +2409,13 @@ subgraph_from_edges <- function( # Argument checks # Argument checks ensure_igraph(graph) - eids <- as_igraph_es(graph, eids) + edges <- as_igraph_es(graph, edges) delete.vertices <- as.logical(delete.vertices) # Function call res <- subgraph_from_edges_impl( graph = graph, - eids = eids, + eids = edges, delete_vertices = delete.vertices ) @@ -3973,8 +4016,9 @@ girth <- function( #' original multiplicity as an edge attribute. #' #' @param graph The input graph. -#' @param eids The edges to which the query is restricted. The default +#' @param edges The edges to which the query is restricted. The default #' `NULL` selects all edges. +#' @param eids `r lifecycle::badge("deprecated")` Use `edges` instead. #' @return `any_loop()` and `any_multiple()` return a Logical. #' `which_loop()` and `which_multiple()` return a logical vector. #' `count_loops()` returns a numeric scalar with the total number of loop edges. @@ -4011,14 +4055,29 @@ girth <- function( #' any(which_multiple(g)) #' E(g)$weight #' -which_multiple <- function(graph, eids = NULL) { - if (is.null(eids)) { - eids <- E(graph) +which_multiple <- function(graph, edges = NULL, eids = deprecated()) { + if (lifecycle::is_present(eids)) { + if (!missing(edges)) { + cli::cli_abort(c( + "Argument {.arg edges} of {.fn which_multiple} was supplied more than once.", + i = "It was also supplied via its legacy name {.arg eids}." + )) + } + lifecycle::deprecate_soft( + "3.0.0", + "which_multiple(eids = )", + "which_multiple(edges = )" + ) + edges <- eids + } + + if (is.null(edges)) { + edges <- E(graph) } is_multiple_impl( graph = graph, - eids = eids + eids = edges ) } #' @rdname which_multiple @@ -4030,26 +4089,56 @@ any_multiple <- function(graph) { } #' @rdname which_multiple #' @export -count_multiple <- function(graph, eids = NULL) { - if (is.null(eids)) { - eids <- E(graph) +count_multiple <- function(graph, edges = NULL, eids = deprecated()) { + if (lifecycle::is_present(eids)) { + if (!missing(edges)) { + cli::cli_abort(c( + "Argument {.arg edges} of {.fn count_multiple} was supplied more than once.", + i = "It was also supplied via its legacy name {.arg eids}." + )) + } + lifecycle::deprecate_soft( + "3.0.0", + "count_multiple(eids = )", + "count_multiple(edges = )" + ) + edges <- eids + } + + if (is.null(edges)) { + edges <- E(graph) } count_multiple_impl( graph = graph, - eids = eids + eids = edges ) } #' @rdname which_multiple #' @export -which_loop <- function(graph, eids = NULL) { - if (is.null(eids)) { - eids <- E(graph) +which_loop <- function(graph, edges = NULL, eids = deprecated()) { + if (lifecycle::is_present(eids)) { + if (!missing(edges)) { + cli::cli_abort(c( + "Argument {.arg edges} of {.fn which_loop} was supplied more than once.", + i = "It was also supplied via its legacy name {.arg eids}." + )) + } + lifecycle::deprecate_soft( + "3.0.0", + "which_loop(eids = )", + "which_loop(edges = )" + ) + edges <- eids + } + + if (is.null(edges)) { + edges <- E(graph) } is_loop_impl( graph = graph, - eids = eids + eids = edges ) } #' @rdname which_multiple @@ -5362,8 +5451,9 @@ max_bipartite_match <- function( #' Undirected graphs contain only mutual edges by definition. #' #' @param graph The input graph. -#' @param eids Edge sequence, the edges that will be probed. The default +#' @param edges Edge sequence, the edges that will be probed. The default #' `NULL` includes all edges in the order of their IDs. +#' @param eids `r lifecycle::badge("deprecated")` Use `edges` instead. #' @inheritParams rlang::args_dots_empty #' @param loops Logical, whether to consider directed self-loops to be mutual. #' @return A logical vector of the same length as the number of edges supplied. @@ -5382,13 +5472,55 @@ max_bipartite_match <- function( #' @export which_mutual <- function( graph, - eids = NULL, + edges = NULL, ..., - loops = TRUE + loops = TRUE, + eids = deprecated() ) { # BEGIN GENERATED ARG_HANDLE: which_mutual, do not edit, see tools/generate-migrations.R # fmt: skip - if (...length() > 0L) { + if (!base::missing(eids)) { + # Pre-3.0.0 signature: which_mutual(graph, eids, loops) + .legacy_signature <- function(graph, eids, loops, ...) { + base::list(env = base::environment(), n_extra = ...length(), extra = base::as.character(base::names(base::substitute(...()))), recovered = base::c( + if (!base::missing(graph)) base::c(graph = "graph"), + if (!base::missing(eids)) base::c(edges = "eids"), + if (!base::missing(loops)) base::c(loops = "loops") + )) + } + .arg_call <- base::sys.call() + .arg_call[[1L]] <- .legacy_signature + .arg_handle <- base::eval(.arg_call, base::parent.frame()) + .arg_extra <- .arg_handle$extra + if (.arg_handle$n_extra > base::sum(base::nzchar(.arg_extra))) cli::cli_abort("Too many arguments passed to {.fn which_mutual}.") + .arg_explicit <- base::c("graph", "edges", "loops", "eids")[base::pmatch(.arg_extra, base::c("graph", "edges", "loops", "eids"), duplicates.ok = TRUE)] + if (base::anyNA(.arg_explicit)) cli::cli_abort("Unexpected argument passed to {.fn which_mutual}: {.arg {(.arg_extra[base::is.na(.arg_explicit)])}}.") + .arg_recovered <- .arg_handle$recovered + .arg_names <- base::names(.arg_recovered) + .arg_conflict <- base::intersect(.arg_names, .arg_explicit) + if (base::length(.arg_conflict) > 0L) { + .arg_conflict <- .arg_conflict[[1L]] + .arg_via <- .arg_recovered[[.arg_conflict]] + cli::cli_abort(base::c("Argument {.arg {(.arg_conflict)}} of {.fn which_mutual} was supplied more than once.", i = if (base::is.element(.arg_via, base::names(.arg_call))) "It was also supplied via its legacy name {.arg {(.arg_via)}}." else "It was also passed by position, as {.arg {(.arg_via)}} of the old signature.")) + } + for (.arg_i in base::seq_along(.arg_recovered)) base::do.call(base::delayedAssign, base::list(.arg_names[[.arg_i]], base::call("[[", .arg_handle$env, .arg_recovered[[.arg_i]]), base::baseenv(), base::environment())) + if (!base::missing(eids)) lifecycle::deprecate_soft("3.0.0", "which_mutual(eids = )", "which_mutual(edges = )") + .arg_tail <- .arg_recovered[base::is.element(.arg_recovered, base::c("loops"))] + .arg_tail <- .arg_tail[!base::is.element(.arg_tail, base::names(.arg_call)) | base::names(.arg_tail) != .arg_tail] + if (base::length(.arg_tail) > 0L) { + .arg_shown <- base::ifelse(base::is.element(.arg_tail, base::names(.arg_call)), base::paste0(.arg_tail, " = "), .arg_tail) + lifecycle::deprecate_soft( + "3.0.0", + what = base::I("Calling `which_mutual()` with positional, abbreviated or renamed arguments"), + details = base::c( + i = base::paste0("Detected call: which_mutual(", base::paste(base::c("graph", "edges", .arg_shown), collapse = ", "), ")"), + i = base::paste0("Use instead: which_mutual(", base::paste(base::c("graph", "edges", base::paste0(base::names(.arg_tail), " = ")), collapse = ", "), ")") + ) + ) + } + } else if (...length() > 0L) { + .arg_forbidden <- base::intersect(base::names(base::sys.call()), base::c("e")) + if (base::length(.arg_forbidden) > 0L) cli::cli_abort(base::c("Argument {.arg {(.arg_forbidden)}} matches multiple formal arguments of {.fn which_mutual}.", i = "Spell out the full argument name.")) # Pre-3.0.0 signature: which_mutual(graph, eids, loops) .old_signature <- function(loops, ...) { if (...length() > 0L) { @@ -5418,21 +5550,21 @@ which_mutual <- function( "3.0.0", what = base::I("Calling `which_mutual()` with positional or abbreviated arguments"), details = base::c( - i = base::paste0("Detected call: which_mutual(", base::paste(base::c("graph", "eids", .arg_shown), collapse = ", "), ")"), - i = base::paste0("Use instead: which_mutual(", base::paste(base::c("graph", "eids", base::paste0(.arg_names, " = ")), collapse = ", "), ")") + i = base::paste0("Detected call: which_mutual(", base::paste(base::c("graph", "edges", .arg_shown), collapse = ", "), ")"), + i = base::paste0("Use instead: which_mutual(", base::paste(base::c("graph", "edges", base::paste0(.arg_names, " = ")), collapse = ", "), ")") ) ) } } # END GENERATED ARG_HANDLE - if (is.null(eids)) { - eids <- E(graph) + if (is.null(edges)) { + edges <- E(graph) } is_mutual_impl( graph = graph, - eids = eids, + eids = edges, loops = loops ) } diff --git a/man/betweenness.Rd b/man/betweenness.Rd index 886c5b6fa9..36899c831b 100644 --- a/man/betweenness.Rd +++ b/man/betweenness.Rd @@ -20,11 +20,12 @@ betweenness( edge_betweenness( graph, - e = NULL, + edges = NULL, ..., directed = TRUE, weights = NULL, - cutoff = -1 + cutoff = -1, + e = deprecated() ) } \arguments{ @@ -60,14 +61,16 @@ betweenness. If negative, then there is no such limit.} \item{v}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} Use \code{vertices} instead.} -\item{e}{The edges for which the edge betweenness will be calculated. +\item{edges}{The edges for which the edge betweenness will be calculated. The default \code{NULL} selects all edges.} + +\item{e}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} Use \code{edges} instead.} } \value{ A numeric vector with the betweenness score for each vertex in \code{vertices} for \code{betweenness()}. -A numeric vector with the edge betweenness score for each edge in \code{e} +A numeric vector with the edge betweenness score for each edge in \code{edges} for \code{edge_betweenness()}. } \description{ diff --git a/man/count.multiple.Rd b/man/count.multiple.Rd index a4e624fe0c..d97bbb990f 100644 --- a/man/count.multiple.Rd +++ b/man/count.multiple.Rd @@ -9,8 +9,7 @@ count.multiple(graph, eids = E(graph)) \arguments{ \item{graph}{The input graph.} -\item{eids}{The edges to which the query is restricted. The default -\code{NULL} selects all edges.} +\item{eids}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} Use \code{edges} instead.} } \description{ \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} diff --git a/man/edge.betweenness.Rd b/man/edge.betweenness.Rd index a98737cf18..0ec479ca94 100644 --- a/man/edge.betweenness.Rd +++ b/man/edge.betweenness.Rd @@ -15,8 +15,7 @@ edge.betweenness( \arguments{ \item{graph}{The graph to analyze.} -\item{e}{The edges for which the edge betweenness will be calculated. -The default \code{NULL} selects all edges.} +\item{e}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} Use \code{edges} instead.} \item{directed}{Logical, whether directed paths should be considered while determining the shortest paths.} diff --git a/man/ends.Rd b/man/ends.Rd index be8c438198..2fb27f521b 100644 --- a/man/ends.Rd +++ b/man/ends.Rd @@ -5,17 +5,19 @@ \alias{get.edges} \title{Incident vertices of some graph edges} \usage{ -ends(graph, es, ..., names = TRUE) +ends(graph, edges, ..., names = TRUE, es = deprecated()) } \arguments{ \item{graph}{The input graph} -\item{es}{The sequence of edges to query} +\item{edges}{The sequence of edges to query} \item{...}{These dots are for future extensions and must be empty.} \item{names}{Whether to return vertex names or numeric vertex IDs. By default vertex names are used.} + +\item{es}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} Use \code{edges} instead.} } \value{ A two column matrix of vertex names or vertex IDs. diff --git a/man/estimate_edge_betweenness.Rd b/man/estimate_edge_betweenness.Rd index acd055427c..e04e407f35 100644 --- a/man/estimate_edge_betweenness.Rd +++ b/man/estimate_edge_betweenness.Rd @@ -15,8 +15,7 @@ estimate_edge_betweenness( \arguments{ \item{graph}{The graph to analyze.} -\item{e}{The edges for which the edge betweenness will be calculated. -The default \code{NULL} selects all edges.} +\item{e}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} Use \code{edges} instead.} \item{directed}{Logical, whether directed paths should be considered while determining the shortest paths.} diff --git a/man/head_of.Rd b/man/head_of.Rd index 4e916b2631..eb29264e59 100644 --- a/man/head_of.Rd +++ b/man/head_of.Rd @@ -4,12 +4,14 @@ \alias{head_of} \title{Head of the edge(s) in a graph} \usage{ -head_of(graph, es) +head_of(graph, edges, es = deprecated()) } \arguments{ \item{graph}{The input graph.} -\item{es}{The edges to query.} +\item{edges}{The edges to query.} + +\item{es}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} Use \code{edges} instead.} } \value{ A vertex sequence with the head(s) of the edge(s). diff --git a/man/is.loop.Rd b/man/is.loop.Rd index ce99c88946..6edd60a140 100644 --- a/man/is.loop.Rd +++ b/man/is.loop.Rd @@ -9,8 +9,7 @@ is.loop(graph, eids = E(graph)) \arguments{ \item{graph}{The input graph.} -\item{eids}{The edges to which the query is restricted. The default -\code{NULL} selects all edges.} +\item{eids}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} Use \code{edges} instead.} } \description{ \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} diff --git a/man/is.multiple.Rd b/man/is.multiple.Rd index 8ea9bd2d76..c3c4ddc8cd 100644 --- a/man/is.multiple.Rd +++ b/man/is.multiple.Rd @@ -9,8 +9,7 @@ is.multiple(graph, eids = E(graph)) \arguments{ \item{graph}{The input graph.} -\item{eids}{The edges to which the query is restricted. The default -\code{NULL} selects all edges.} +\item{eids}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} Use \code{edges} instead.} } \description{ \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} diff --git a/man/is.mutual.Rd b/man/is.mutual.Rd index 321108ac67..37b1dc1cf7 100644 --- a/man/is.mutual.Rd +++ b/man/is.mutual.Rd @@ -9,8 +9,7 @@ is.mutual(graph, eids = E(graph), loops = TRUE) \arguments{ \item{graph}{The input graph.} -\item{eids}{Edge sequence, the edges that will be probed. The default -\code{NULL} includes all edges in the order of their IDs.} +\item{eids}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} Use \code{edges} instead.} \item{loops}{Logical, whether to consider directed self-loops to be mutual.} } diff --git a/man/reverse_edges.Rd b/man/reverse_edges.Rd index f4d0cd085f..08488ebddf 100644 --- a/man/reverse_edges.Rd +++ b/man/reverse_edges.Rd @@ -5,16 +5,18 @@ \alias{t.igraph} \title{Reverse edges in a graph} \usage{ -reverse_edges(graph, eids = NULL) +reverse_edges(graph, edges = NULL, eids = deprecated()) \method{t}{igraph}(x) } \arguments{ \item{graph}{The input graph.} -\item{eids}{The edge IDs of the edges to reverse. The default \code{NULL} +\item{edges}{The edge IDs of the edges to reverse. The default \code{NULL} reverses all edges.} +\item{eids}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} Use \code{edges} instead.} + \item{x}{The input graph.} } \value{ @@ -24,7 +26,7 @@ IDs are reversed \description{ The new graph will contain the same vertices, edges and attributes as the original graph, except that the direction of the edges selected by -their edge IDs in the \code{eids} argument will be reversed. When reversing +their edge IDs in the \code{edges} argument will be reversed. When reversing all edges, this operation is also known as graph transpose. } \section{Related documentation in the C library}{ diff --git a/man/subgraph.Rd b/man/subgraph.Rd index 7718376969..8771632cae 100644 --- a/man/subgraph.Rd +++ b/man/subgraph.Rd @@ -16,7 +16,13 @@ induced_subgraph( vids = deprecated() ) -subgraph_from_edges(graph, eids, ..., delete.vertices = TRUE) +subgraph_from_edges( + graph, + edges, + ..., + delete.vertices = TRUE, + eids = deprecated() +) } \arguments{ \item{graph}{The original graph.} @@ -37,10 +43,12 @@ scratch. \sQuote{\code{auto}} chooses between the two implementations automatically, using heuristics based on the size of the original and the result graph.} -\item{eids}{The edge IDs of the edges that will be kept in the result graph.} +\item{edges}{The edge IDs of the edges that will be kept in the result graph.} \item{delete.vertices}{Logical, whether to remove vertices that do -not have any adjacent edges in \code{eids}.} +not have any adjacent edges in \code{edges}.} + +\item{eids}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} Use \code{edges} instead.} } \value{ A new graph object. diff --git a/man/subgraph.edges.Rd b/man/subgraph.edges.Rd index f37718bb42..87eaef774e 100644 --- a/man/subgraph.edges.Rd +++ b/man/subgraph.edges.Rd @@ -9,10 +9,10 @@ subgraph.edges(graph, eids, delete.vertices = TRUE) \arguments{ \item{graph}{The original graph.} -\item{eids}{The edge IDs of the edges that will be kept in the result graph.} +\item{eids}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} Use \code{edges} instead.} \item{delete.vertices}{Logical, whether to remove vertices that do -not have any adjacent edges in \code{eids}.} +not have any adjacent edges in \code{edges}.} } \description{ \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} diff --git a/man/tail_of.Rd b/man/tail_of.Rd index 91f16cab2a..fb176dde06 100644 --- a/man/tail_of.Rd +++ b/man/tail_of.Rd @@ -4,12 +4,14 @@ \alias{tail_of} \title{Tails of the edge(s) in a graph} \usage{ -tail_of(graph, es) +tail_of(graph, edges, es = deprecated()) } \arguments{ \item{graph}{The input graph.} -\item{es}{The edges to query.} +\item{edges}{The edges to query.} + +\item{es}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} Use \code{edges} instead.} } \value{ A vertex sequence with the tail(s) of the edge(s). diff --git a/man/which_multiple.Rd b/man/which_multiple.Rd index 4d166b4a5a..8fa03ad52c 100644 --- a/man/which_multiple.Rd +++ b/man/which_multiple.Rd @@ -9,13 +9,13 @@ \alias{count_loops} \title{Find the multiple or loop edges in a graph} \usage{ -which_multiple(graph, eids = NULL) +which_multiple(graph, edges = NULL, eids = deprecated()) any_multiple(graph) -count_multiple(graph, eids = NULL) +count_multiple(graph, edges = NULL, eids = deprecated()) -which_loop(graph, eids = NULL) +which_loop(graph, edges = NULL, eids = deprecated()) any_loop(graph) @@ -24,8 +24,10 @@ count_loops(graph) \arguments{ \item{graph}{The input graph.} -\item{eids}{The edges to which the query is restricted. The default +\item{edges}{The edges to which the query is restricted. The default \code{NULL} selects all edges.} + +\item{eids}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} Use \code{edges} instead.} } \value{ \code{any_loop()} and \code{any_multiple()} return a Logical. diff --git a/man/which_mutual.Rd b/man/which_mutual.Rd index 46346529c7..a9ed74426e 100644 --- a/man/which_mutual.Rd +++ b/man/which_mutual.Rd @@ -4,17 +4,19 @@ \alias{which_mutual} \title{Find mutual edges in a directed graph} \usage{ -which_mutual(graph, eids = NULL, ..., loops = TRUE) +which_mutual(graph, edges = NULL, ..., loops = TRUE, eids = deprecated()) } \arguments{ \item{graph}{The input graph.} -\item{eids}{Edge sequence, the edges that will be probed. The default +\item{edges}{Edge sequence, the edges that will be probed. The default \code{NULL} includes all edges in the order of their IDs.} \item{...}{These dots are for future extensions and must be empty.} \item{loops}{Logical, whether to consider directed self-loops to be mutual.} + +\item{eids}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} Use \code{edges} instead.} } \value{ A logical vector of the same length as the number of edges supplied. diff --git a/tests/testthat/_snaps/basic.md b/tests/testthat/_snaps/basic.md new file mode 100644 index 0000000000..6aeac095b4 --- /dev/null +++ b/tests/testthat/_snaps/basic.md @@ -0,0 +1,18 @@ +# head_of(es = ) and tail_of(es = ) are deprecated but still work + + Code + res <- head_of(g, es = E(g)) + Condition + Warning: + The `es` argument of `head_of()` is deprecated as of igraph 3.0.0. + i Please use the `edges` argument instead. + +--- + + Code + head_of(g, edges = 1, es = 2) + Condition + Error in `head_of()`: + ! Argument `edges` of `head_of()` was supplied more than once. + i It was also supplied via its legacy name `es`. + diff --git a/tests/testthat/_snaps/structural-properties.md b/tests/testthat/_snaps/structural-properties.md index 36fd527599..b40a478dae 100644 --- a/tests/testthat/_snaps/structural-properties.md +++ b/tests/testthat/_snaps/structural-properties.md @@ -120,3 +120,12 @@ ! Argument `vertices` of `degree()` was supplied more than once. i It was also supplied via its legacy name `v`. +# edge queries with `eids = ` are deprecated but still work + + Code + res <- which_multiple(g, eids = 4:5) + Condition + Warning: + The `eids` argument of `which_multiple()` is deprecated as of igraph 3.0.0. + i Please use the `edges` argument instead. + diff --git a/tests/testthat/_snaps/trees.md b/tests/testthat/_snaps/trees.md index 91a639c3a3..59f2f7cc2b 100644 --- a/tests/testthat/_snaps/trees.md +++ b/tests/testthat/_snaps/trees.md @@ -6,6 +6,9 @@ Warning: `subgraph.edges()` was deprecated in igraph 2.1.0. i Please use `subgraph_from_edges()` instead. + Warning: + The `eids` argument of `subgraph_from_edges()` is deprecated as of igraph 3.0.0. + i Please use the `edges` argument instead. Output IGRAPH U--- 13 11 -- + attr: name_1 (g/c), name_2 (g/c), loops_1 (g/l), loops_2 (g/l) diff --git a/tests/testthat/test-basic.R b/tests/testthat/test-basic.R new file mode 100644 index 0000000000..f7ec2017df --- /dev/null +++ b/tests/testthat/test-basic.R @@ -0,0 +1,15 @@ +test_that("head_of() and tail_of() work", { + g <- make_graph(c(1, 2, 2, 3), directed = TRUE) + expect_equal(as.numeric(head_of(g, E(g))), c(2, 3)) + expect_equal(as.numeric(tail_of(g, E(g))), c(1, 2)) +}) + +test_that("head_of(es = ) and tail_of(es = ) are deprecated but still work", { + rlang::local_options(lifecycle_verbosity = "warning") + g <- make_graph(c(1, 2, 2, 3), directed = TRUE) + expect_snapshot_igraph(res <- head_of(g, es = E(g))) + expect_equal(res, head_of(g, edges = E(g))) + lifecycle::expect_deprecated(res <- tail_of(g, es = E(g))) + expect_equal(res, tail_of(g, edges = E(g))) + expect_snapshot_igraph_error(head_of(g, edges = 1, es = 2)) +}) diff --git a/tests/testthat/test-centrality.R b/tests/testthat/test-centrality.R index 5f6a1b84c4..a94168d028 100644 --- a/tests/testthat/test-centrality.R +++ b/tests/testthat/test-centrality.R @@ -1041,7 +1041,7 @@ test_that("edge_betweenness() covers migrated tail args and positional recovery" res <- edge_betweenness( ring, - e = E(ring)[1:3], + edges = E(ring)[1:3], directed = FALSE, weights = rep(1, 5), cutoff = -1 @@ -1050,7 +1050,12 @@ test_that("edge_betweenness() covers migrated tail args and positional recovery" expect_equal(res, rep(3, 3)) # With a cutoff of 1 each edge only carries the path of its endpoints. expect_equal( - edge_betweenness(ring, e = E(ring)[1:3], weights = rep(1, 5), cutoff = 1), + edge_betweenness( + ring, + edges = E(ring)[1:3], + weights = rep(1, 5), + cutoff = 1 + ), rep(1, 3) ) @@ -1367,6 +1372,13 @@ test_that("page_rank(vids = ) is recovered as `vertices`", { expect_identical(res_legacy, page_rank(g, vertices = 1:3)) }) +test_that("edge_betweenness(e = ) is deprecated but still works", { + rlang::local_options(lifecycle_verbosity = "warning") + g <- make_ring(5) + lifecycle::expect_deprecated(res <- edge_betweenness(g, e = E(g)[1:2])) + expect_equal(res, edge_betweenness(g, edges = E(g)[1:2])) +}) + # ---- C core behaviour pins ---------------------------------------------- # These pin the behaviour of the vendored C core, # so that the vendor commit that changes it also flips the expectation. diff --git a/tests/testthat/test-constant-defaults.R b/tests/testthat/test-constant-defaults.R index 0227b4417f..06f3fbcc34 100644 --- a/tests/testthat/test-constant-defaults.R +++ b/tests/testthat/test-constant-defaults.R @@ -12,7 +12,7 @@ test_that("NULL selector defaults stand for the full vertex/edge set", { expect_identical(degree(g, vertices = NULL), degree(g)) expect_identical(distances(g, vertices = NULL, to = NULL), distances(g)) expect_identical(diversity(g, vertices = NULL), diversity(g)) - expect_identical(which_mutual(g, eids = NULL), which_mutual(g)) + expect_identical(which_mutual(g, edges = NULL), which_mutual(g)) expect_identical(closeness(g, vertices = NULL), closeness(g)) }) @@ -34,13 +34,13 @@ test_that("NULL selector defaults of round-2 functions select the full set", { g <- make_ring(5) expect_identical(max_degree(g, vertices = NULL), max_degree(g)) - expect_identical(which_loop(g, eids = NULL), which_loop(g)) - expect_identical(which_multiple(g, eids = NULL), which_multiple(g)) - expect_identical(count_multiple(g, eids = NULL), count_multiple(g)) + expect_identical(which_loop(g, edges = NULL), which_loop(g)) + expect_identical(which_multiple(g, edges = NULL), which_multiple(g)) + expect_identical(count_multiple(g, edges = NULL), count_multiple(g)) expect_identical(count_triangles(g, vertices = NULL), count_triangles(g)) expect_identical(cocitation(g, vertices = NULL), cocitation(g)) expect_identical(similarity(g, vertices = NULL), similarity(g)) - expect_identical_graphs(reverse_edges(g, eids = NULL), reverse_edges(g)) + expect_identical_graphs(reverse_edges(g, edges = NULL), reverse_edges(g)) V(g)$name <- letters[1:5] expect_identical(vertex_attr(g, "name", index = NULL), vertex_attr(g, "name")) @@ -83,7 +83,7 @@ test_that("empty-sequence defaults are spelled as typed empty vectors", { # while NULL now always means "use the default". g <- make_graph(c(1, 2, 2, 2, 2, 3), directed = TRUE) expect_equal(max_degree(g, vertices = integer()), 0) - expect_identical(which_loop(g, eids = integer()), logical(0)) + expect_identical(which_loop(g, edges = integer()), logical(0)) expect_gt(max_degree(g, vertices = NULL), 0) # layout_as_tree(): the typed empty stays the documented default diff --git a/tests/testthat/test-interface.R b/tests/testthat/test-interface.R index ec6e117f59..f37e31a997 100644 --- a/tests/testthat/test-interface.R +++ b/tests/testthat/test-interface.R @@ -470,11 +470,11 @@ test_that("ends() tail arguments and legacy positional recovery", { # The endpoint matrix contains vertex names with names = TRUE # and vertex IDs with names = FALSE. expect_equal( - ends(g, es = 1:2), + ends(g, edges = 1:2), matrix(c("a", "b", "b", "c"), nrow = 2) ) expect_equal( - ends(g, es = 1:2, names = FALSE), + ends(g, edges = 1:2, names = FALSE), matrix(c(1, 2, 2, 3), nrow = 2) ) @@ -529,6 +529,13 @@ test_that("neighbors(v = ) and incident(v = ) are deprecated but still work", { expect_snapshot_igraph_error(neighbors(g, vertex = 1, v = 2)) }) +test_that("ends(es = ) is deprecated but still works", { + rlang::local_options(lifecycle_verbosity = "warning") + g <- make_ring(5) + lifecycle::expect_deprecated(res <- ends(g, es = 1:2)) + expect_equal(res, ends(g, edges = 1:2)) +}) + test_that("incident_edges(v = ) is deprecated but still works", { rlang::local_options(lifecycle_verbosity = "warning") g <- make_ring(10) diff --git a/tests/testthat/test-operators.R b/tests/testthat/test-operators.R index bfeb7bd37c..5f5f5659a3 100644 --- a/tests/testthat/test-operators.R +++ b/tests/testthat/test-operators.R @@ -1575,3 +1575,10 @@ test_that("compose() recovers legacy positional arguments", { compose(g1, g2, byname = FALSE, edge_attr_combine = "concat") ) }) + +test_that("reverse_edges(eids = ) is deprecated but still works", { + rlang::local_options(lifecycle_verbosity = "warning") + g <- make_graph(c(1, 2, 2, 3), directed = TRUE) + lifecycle::expect_deprecated(res <- reverse_edges(g, eids = 1)) + expect_identical_graphs(res, reverse_edges(g, edges = 1)) +}) diff --git a/tests/testthat/test-structural-properties.R b/tests/testthat/test-structural-properties.R index 0557f8d78b..a6ba3feff8 100644 --- a/tests/testthat/test-structural-properties.R +++ b/tests/testthat/test-structural-properties.R @@ -1565,7 +1565,7 @@ test_that("which_mutual() tail arguments and legacy positional recovery", { # loops = FALSE stops counting the self-loop as mutual. expect_equal( - which_mutual(g, eids = E(g), loops = FALSE), + which_mutual(g, edges = E(g), loops = FALSE), c(TRUE, TRUE, FALSE) ) @@ -1664,6 +1664,22 @@ test_that("subcomponent(v = ) is deprecated but still works", { expect_equal(res_legacy, subcomponent(g, vertex = 2, mode = "out")) }) +test_that("edge queries with `eids = ` are deprecated but still work", { + rlang::local_options(lifecycle_verbosity = "warning") + g <- make_graph(c(1, 2, 2, 1, 1, 1, 2, 3, 2, 3), directed = TRUE) + + expect_snapshot_igraph(res <- which_multiple(g, eids = 4:5)) + expect_equal(res, which_multiple(g, edges = 4:5)) + lifecycle::expect_deprecated(res <- count_multiple(g, eids = 4:5)) + expect_equal(res, count_multiple(g, edges = 4:5)) + lifecycle::expect_deprecated(res <- which_loop(g, eids = 3)) + expect_equal(res, which_loop(g, edges = 3)) + lifecycle::expect_deprecated(res <- which_mutual(g, eids = 1:2)) + expect_equal(res, which_mutual(g, edges = 1:2)) + lifecycle::expect_deprecated(res <- subgraph_from_edges(g, eids = 1:2)) + expect_identical_graphs(res, subgraph_from_edges(g, edges = 1:2)) +}) + test_that("constraint(), ego_size(), make_ego_graph() and knn() accept their legacy selector names with a deprecation", { rlang::local_options(lifecycle_verbosity = "warning") g <- make_graph("zachary") diff --git a/tools/migrations/centrality.R b/tools/migrations/centrality.R index 3dde39758b..993c1af458 100644 --- a/tools/migrations/centrality.R +++ b/tools/migrations/centrality.R @@ -65,11 +65,12 @@ migrations <- list( old = function(graph, e, directed, weights, cutoff) {}, new = function( graph, - e = NULL, + edges = NULL, ..., directed = TRUE, weights = NULL, - cutoff = -1 + cutoff = -1, + e = deprecated() ) {}, when = "3.0.0" ), diff --git a/tools/migrations/interface.R b/tools/migrations/interface.R index a4f2684917..600b099634 100644 --- a/tools/migrations/interface.R +++ b/tools/migrations/interface.R @@ -19,9 +19,10 @@ migrations <- list( old = function(graph, es, names) {}, new = function( graph, - es, + edges, ..., - names = TRUE + names = TRUE, + es = deprecated() ) {}, when = "3.0.0" ), diff --git a/tools/migrations/structural-properties.R b/tools/migrations/structural-properties.R index d54b93bbda..de38ccdd96 100644 --- a/tools/migrations/structural-properties.R +++ b/tools/migrations/structural-properties.R @@ -405,9 +405,10 @@ migrations <- list( old = function(graph, eids, delete.vertices) {}, new = function( graph, - eids, + edges, ..., - delete.vertices = TRUE + delete.vertices = TRUE, + eids = deprecated() ) {}, when = "3.0.0" ), @@ -461,9 +462,10 @@ migrations <- list( old = function(graph, eids, loops) {}, new = function( graph, - eids = NULL, + edges = NULL, ..., - loops = TRUE + loops = TRUE, + eids = deprecated() ) {}, when = "3.0.0" )