diff --git a/R/community.R b/R/community.R index a20e76e19f..6837f2163b 100644 --- a/R/community.R +++ b/R/community.R @@ -1781,7 +1781,7 @@ cluster_spinglass <- function( #' @param initial_membership If provided, the Leiden algorithm #' will try to improve this provided membership. If no argument is #' provided, the aglorithm simply starts from the singleton partition. -#' @param n_iterations the number of iterations to iterate the Leiden +#' @param n_iter the number of iterations to iterate the Leiden #' algorithm. Each iteration may improve the partition further. #' @param vertex_weights the vertex weights used in the Leiden algorithm. #' If this is not provided, it will be automatically determined on the basis @@ -1829,7 +1829,7 @@ cluster_leiden <- function( resolution_parameter = deprecated(), beta = 0.01, initial_membership = NULL, - n_iterations = 2, + n_iter = 2, vertex_weights = NULL ) { # BEGIN GENERATED ARG_HANDLE: cluster_leiden, do not edit, see tools/generate-migrations.R @@ -1850,7 +1850,7 @@ cluster_leiden <- function( if (!base::missing(resolution_parameter)) base::c(resolution_parameter = "resolution_parameter"), if (!base::missing(beta)) base::c(beta = "beta"), if (!base::missing(initial_membership)) base::c(initial_membership = "initial_membership"), - if (!base::missing(n_iterations)) base::c(n_iterations = "n_iterations"), + if (!base::missing(n_iterations)) base::c(n_iter = "n_iterations"), if (!base::missing(vertex_weights)) base::c(vertex_weights = "vertex_weights") )) } @@ -1859,13 +1859,16 @@ cluster_leiden <- function( if (!base::missing(resolution_parameter)) "resolution_parameter", if (!base::missing(beta)) "beta", if (!base::missing(initial_membership)) "initial_membership", - if (!base::missing(n_iterations)) "n_iterations", if (!base::missing(vertex_weights)) "vertex_weights" ) .arg_handle <- base::eval(base::as.call(base::c(base::quote(.old_signature), base::structure(base::rep(base::list(NULL), base::length(.arg_given)), names = .arg_given), base::quote(...)))) .arg_recovered <- .arg_handle$recovered[!base::is.element(.arg_handle$recovered, .arg_given)] if (base::length(.arg_recovered) > 0L) { .arg_names <- base::names(.arg_recovered) + .arg_conflict <- base::intersect(.arg_names, base::c( + if (!base::missing(n_iter)) "n_iter" + )) + if (base::length(.arg_conflict) > 0L) cli::cli_abort(base::c("Argument {.arg {(.arg_conflict)}} of {.fn cluster_leiden} was supplied more than once.", i = "Pass it exactly once, by its new name {.arg {(.arg_conflict)}}.")) 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())) .arg_dots <- base::substitute(...()) .arg_tags <- base::as.character(base::names(.arg_dots)) @@ -1874,7 +1877,7 @@ cluster_leiden <- function( .arg_shown <- base::ifelse(base::is.na(.arg_tag_of), .arg_recovered, base::paste0(.arg_tag_of, " = ")) lifecycle::deprecate_soft( "3.0.0", - what = base::I("Calling `cluster_leiden()` with positional or abbreviated arguments"), + what = base::I("Calling `cluster_leiden()` with positional, abbreviated or renamed arguments"), details = base::c( i = base::paste0("Detected call: cluster_leiden(", base::paste(base::c("graph", "objective_function", .arg_shown), collapse = ", "), ")"), i = base::paste0("Use instead: cluster_leiden(", base::paste(base::c("graph", "objective_function", base::paste0(.arg_names, " = ")), collapse = ", "), ")") @@ -1943,7 +1946,7 @@ cluster_leiden <- function( } membership <- initial_membership - if (n_iterations > 0) { + if (n_iter > 0) { res <- community_leiden_impl( graph = graph, weights = weights, @@ -1951,7 +1954,7 @@ cluster_leiden <- function( resolution = resolution, beta = beta, start = !is.null(membership), - n_iterations = n_iterations, + n_iterations = n_iter, membership = membership ) diff --git a/R/glet.R b/R/glet.R index 86ae9fdc37..6466e047eb 100644 --- a/R/glet.R +++ b/R/glet.R @@ -68,7 +68,7 @@ graphlets.candidate.basis <- function(graph, weights = NULL) { #' @param weights Edge weights. If the graph has a `weight` edge attribute #' and this argument is `NULL` (the default), then the `weight` edge #' attribute is used. -#' @param niter Integer scalar, the number of iterations to perform. +#' @param n_iter Integer scalar, the number of iterations to perform. #' @param cliques A list of vertex IDs, the graphlet basis to use for the #' projection. #' @param Mu Starting weights for the projection. The default `NULL` uses a @@ -120,7 +120,7 @@ graphlets.candidate.basis <- function(graph, weights = NULL) { #' plot(g, layout = co) #' #' ## Calculate graphlets -#' gl <- graphlets(g, niter = 1000) +#' gl <- graphlets(g, n_iter = 1000) #' #' ## Plot graphlets #' for (i in seq_along(gl$cliques)) { @@ -196,7 +196,7 @@ graphlet_proj <- function( ..., weights = NULL, cliques, - niter = 1000, + n_iter = 1000, Mu = NULL ) { # BEGIN GENERATED ARG_HANDLE: graphlet_proj, do not edit, see tools/generate-migrations.R @@ -213,20 +213,23 @@ graphlet_proj <- function( base::list(env = base::environment(), recovered = base::c( if (!base::missing(weights)) base::c(weights = "weights"), if (!base::missing(cliques)) base::c(cliques = "cliques"), - if (!base::missing(niter)) base::c(niter = "niter"), + if (!base::missing(niter)) base::c(n_iter = "niter"), if (!base::missing(Mu)) base::c(Mu = "Mu") )) } .arg_given <- base::c( if (!base::missing(weights)) "weights", if (!base::missing(cliques)) "cliques", - if (!base::missing(niter)) "niter", if (!base::missing(Mu)) "Mu" ) .arg_handle <- base::eval(base::as.call(base::c(base::quote(.old_signature), base::structure(base::rep(base::list(NULL), base::length(.arg_given)), names = .arg_given), base::quote(...)))) .arg_recovered <- .arg_handle$recovered[!base::is.element(.arg_handle$recovered, .arg_given)] if (base::length(.arg_recovered) > 0L) { .arg_names <- base::names(.arg_recovered) + .arg_conflict <- base::intersect(.arg_names, base::c( + if (!base::missing(n_iter)) "n_iter" + )) + if (base::length(.arg_conflict) > 0L) cli::cli_abort(base::c("Argument {.arg {(.arg_conflict)}} of {.fn graphlet_proj} was supplied more than once.", i = "Pass it exactly once, by its new name {.arg {(.arg_conflict)}}.")) 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())) .arg_dots <- base::substitute(...()) .arg_tags <- base::as.character(base::names(.arg_dots)) @@ -235,7 +238,7 @@ graphlet_proj <- function( .arg_shown <- base::ifelse(base::is.na(.arg_tag_of), .arg_recovered, base::paste0(.arg_tag_of, " = ")) lifecycle::deprecate_soft( "3.0.0", - what = base::I("Calling `graphlet_proj()` with positional or abbreviated arguments"), + what = base::I("Calling `graphlet_proj()` with positional, abbreviated or renamed arguments"), details = base::c( i = base::paste0("Detected call: graphlet_proj(", base::paste(base::c("graph", .arg_shown), collapse = ", "), ")"), i = base::paste0("Use instead: graphlet_proj(", base::paste(base::c("graph", base::paste0(.arg_names, " = ")), collapse = ", "), ")") @@ -260,14 +263,14 @@ graphlet_proj <- function( weights <- NULL } Mu <- as.numeric(Mu) - niter <- as.numeric(niter) + n_iter <- as.numeric(n_iter) graphlets_project_impl( graph = graph, weights = weights, cliques = cliques, Muc = Mu, - niter = niter + niter = n_iter ) } @@ -330,7 +333,7 @@ graphlets <- function( graph, ..., weights = NULL, - niter = 1000 + n_iter = 1000 ) { # BEGIN GENERATED ARG_HANDLE: graphlets, do not edit, see tools/generate-migrations.R # fmt: skip @@ -345,17 +348,20 @@ graphlets <- function( } base::list(env = base::environment(), recovered = base::c( if (!base::missing(weights)) base::c(weights = "weights"), - if (!base::missing(niter)) base::c(niter = "niter") + if (!base::missing(niter)) base::c(n_iter = "niter") )) } .arg_given <- base::c( - if (!base::missing(weights)) "weights", - if (!base::missing(niter)) "niter" + if (!base::missing(weights)) "weights" ) .arg_handle <- base::eval(base::as.call(base::c(base::quote(.old_signature), base::structure(base::rep(base::list(NULL), base::length(.arg_given)), names = .arg_given), base::quote(...)))) .arg_recovered <- .arg_handle$recovered[!base::is.element(.arg_handle$recovered, .arg_given)] if (base::length(.arg_recovered) > 0L) { .arg_names <- base::names(.arg_recovered) + .arg_conflict <- base::intersect(.arg_names, base::c( + if (!base::missing(n_iter)) "n_iter" + )) + if (base::length(.arg_conflict) > 0L) cli::cli_abort(base::c("Argument {.arg {(.arg_conflict)}} of {.fn graphlets} was supplied more than once.", i = "Pass it exactly once, by its new name {.arg {(.arg_conflict)}}.")) 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())) .arg_dots <- base::substitute(...()) .arg_tags <- base::as.character(base::names(.arg_dots)) @@ -364,7 +370,7 @@ graphlets <- function( .arg_shown <- base::ifelse(base::is.na(.arg_tag_of), .arg_recovered, base::paste0(.arg_tag_of, " = ")) lifecycle::deprecate_soft( "3.0.0", - what = base::I("Calling `graphlets()` with positional or abbreviated arguments"), + what = base::I("Calling `graphlets()` with positional, abbreviated or renamed arguments"), details = base::c( i = base::paste0("Detected call: graphlets(", base::paste(base::c("graph", .arg_shown), collapse = ", "), ")"), i = base::paste0("Use instead: graphlets(", base::paste(base::c("graph", base::paste0(.arg_names, " = ")), collapse = ", "), ")") @@ -377,6 +383,6 @@ graphlets <- function( graphlets_impl( graph = graph, weights = weights, - niter = niter + niter = n_iter ) } diff --git a/R/layout.R b/R/layout.R index 13a34b2e00..818b576ef3 100644 --- a/R/layout.R +++ b/R/layout.R @@ -696,7 +696,7 @@ normalize <- function( #' @param hgap Real scalar, the minimum horizontal gap between vertices in the #' same layer. #' @param vgap Real scalar, the distance between the two layers. -#' @param maxiter Integer scalar, the maximum number of iterations in the +#' @param max_iter Integer scalar, the maximum number of iterations in the #' crossing minimization stage. 100 is a reasonable default; if you feel that #' you have too many edge crossings, increase this. #' @return A matrix with two columns and as many rows as the number of vertices @@ -726,7 +726,7 @@ layout_as_bipartite <- function( ..., hgap = 1, vgap = 1, - maxiter = 100 + max_iter = 100 ) { # BEGIN GENERATED ARG_HANDLE: layout_as_bipartite, do not edit, see tools/generate-migrations.R # fmt: skip @@ -742,18 +742,21 @@ layout_as_bipartite <- function( base::list(env = base::environment(), recovered = base::c( if (!base::missing(hgap)) base::c(hgap = "hgap"), if (!base::missing(vgap)) base::c(vgap = "vgap"), - if (!base::missing(maxiter)) base::c(maxiter = "maxiter") + if (!base::missing(maxiter)) base::c(max_iter = "maxiter") )) } .arg_given <- base::c( if (!base::missing(hgap)) "hgap", - if (!base::missing(vgap)) "vgap", - if (!base::missing(maxiter)) "maxiter" + if (!base::missing(vgap)) "vgap" ) .arg_handle <- base::eval(base::as.call(base::c(base::quote(.old_signature), base::structure(base::rep(base::list(NULL), base::length(.arg_given)), names = .arg_given), base::quote(...)))) .arg_recovered <- .arg_handle$recovered[!base::is.element(.arg_handle$recovered, .arg_given)] if (base::length(.arg_recovered) > 0L) { .arg_names <- base::names(.arg_recovered) + .arg_conflict <- base::intersect(.arg_names, base::c( + if (!base::missing(max_iter)) "max_iter" + )) + if (base::length(.arg_conflict) > 0L) cli::cli_abort(base::c("Argument {.arg {(.arg_conflict)}} of {.fn layout_as_bipartite} was supplied more than once.", i = "Pass it exactly once, by its new name {.arg {(.arg_conflict)}}.")) 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())) .arg_dots <- base::substitute(...()) .arg_tags <- base::as.character(base::names(.arg_dots)) @@ -762,7 +765,7 @@ layout_as_bipartite <- function( .arg_shown <- base::ifelse(base::is.na(.arg_tag_of), .arg_recovered, base::paste0(.arg_tag_of, " = ")) lifecycle::deprecate_soft( "3.0.0", - what = base::I("Calling `layout_as_bipartite()` with positional or abbreviated arguments"), + what = base::I("Calling `layout_as_bipartite()` with positional, abbreviated or renamed arguments"), details = base::c( i = base::paste0("Detected call: layout_as_bipartite(", base::paste(base::c("graph", "types", .arg_shown), collapse = ", "), ")"), i = base::paste0("Use instead: layout_as_bipartite(", base::paste(base::c("graph", "types", base::paste0(.arg_names, " = ")), collapse = ", "), ")") @@ -780,7 +783,7 @@ layout_as_bipartite <- function( types = types, hgap = hgap, vgap = vgap, - maxiter = maxiter + maxiter = max_iter ) } @@ -1594,8 +1597,8 @@ layout.random <- function(..., params = list()) { #' @param coords Optional starting positions for the vertices. If this argument #' is not `NULL` then it should be an appropriate matrix of starting #' coordinates. -#' @param maxiter Number of iterations to perform in the first phase. -#' @param fineiter Number of iterations in the fine tuning phase. The +#' @param n_iter Number of iterations to perform in the first phase. +#' @param n_fine_iter Number of iterations in the fine tuning phase. The #' default `NULL` uses `max(10, log2(vcount(graph)))`. #' @param cool.fact Cooling factor. #' @param weight.node.dist Weight for the node-node distances component of the @@ -1687,8 +1690,8 @@ layout_with_dh <- function( graph, ..., coords = NULL, - maxiter = 10, - fineiter = NULL, + n_iter = 10, + n_fine_iter = NULL, cool.fact = 0.75, weight.node.dist = 1.0, weight.border = 0.0, @@ -1699,7 +1702,7 @@ layout_with_dh <- function( # BEGIN GENERATED ARG_HANDLE: layout_with_dh, do not edit, see tools/generate-migrations.R # fmt: skip if (...length() > 0L) { - .arg_ambiguous <- base::intersect(base::names(base::substitute(...())), base::c("c", "co", "coo", "w", "we", "wei", "weig", "weigh", "weight", "weight.", "weight.n", "weight.no", "weight.nod", "weight.node", "weight.node.", "weight.e", "weight.ed", "weight.edg", "weight.edge", "weight.edge.")) + .arg_ambiguous <- base::intersect(base::names(base::substitute(...())), base::c("c", "co", "coo", "n", "n_", "w", "we", "wei", "weig", "weigh", "weight", "weight.", "weight.n", "weight.no", "weight.nod", "weight.node", "weight.node.", "weight.e", "weight.ed", "weight.edg", "weight.edge", "weight.edge.")) if (base::length(.arg_ambiguous) > 0L) cli::cli_abort("Argument {.arg {(.arg_ambiguous[[1L]])}} matches multiple arguments of {.fn layout_with_dh}.") # Pre-3.0.0 signature: layout_with_dh(graph, coords, maxiter, fineiter, cool.fact, weight.node.dist, weight.border, weight.edge.lengths, weight.edge.crossings, weight.node.edge.dist) .old_signature <- function(coords, maxiter, fineiter, cool.fact, weight.node.dist, weight.border, weight.edge.lengths, weight.edge.crossings, weight.node.edge.dist, ...) { @@ -1711,8 +1714,8 @@ layout_with_dh <- function( } base::list(env = base::environment(), recovered = base::c( if (!base::missing(coords)) base::c(coords = "coords"), - if (!base::missing(maxiter)) base::c(maxiter = "maxiter"), - if (!base::missing(fineiter)) base::c(fineiter = "fineiter"), + if (!base::missing(maxiter)) base::c(n_iter = "maxiter"), + if (!base::missing(fineiter)) base::c(n_fine_iter = "fineiter"), if (!base::missing(cool.fact)) base::c(cool.fact = "cool.fact"), if (!base::missing(weight.node.dist)) base::c(weight.node.dist = "weight.node.dist"), if (!base::missing(weight.border)) base::c(weight.border = "weight.border"), @@ -1723,8 +1726,6 @@ layout_with_dh <- function( } .arg_given <- base::c( if (!base::missing(coords)) "coords", - if (!base::missing(maxiter)) "maxiter", - if (!base::missing(fineiter)) "fineiter", if (!base::missing(cool.fact)) "cool.fact", if (!base::missing(weight.node.dist)) "weight.node.dist", if (!base::missing(weight.border)) "weight.border", @@ -1736,6 +1737,11 @@ layout_with_dh <- function( .arg_recovered <- .arg_handle$recovered[!base::is.element(.arg_handle$recovered, .arg_given)] if (base::length(.arg_recovered) > 0L) { .arg_names <- base::names(.arg_recovered) + .arg_conflict <- base::intersect(.arg_names, base::c( + if (!base::missing(n_iter)) "n_iter", + if (!base::missing(n_fine_iter)) "n_fine_iter" + )) + if (base::length(.arg_conflict) > 0L) cli::cli_abort(base::c("Argument {.arg {(.arg_conflict)}} of {.fn layout_with_dh} was supplied more than once.", i = "Pass it exactly once, by its new name {.arg {(.arg_conflict)}}.")) 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())) .arg_dots <- base::substitute(...()) .arg_tags <- base::as.character(base::names(.arg_dots)) @@ -1744,7 +1750,7 @@ layout_with_dh <- function( .arg_shown <- base::ifelse(base::is.na(.arg_tag_of), .arg_recovered, base::paste0(.arg_tag_of, " = ")) lifecycle::deprecate_soft( "3.0.0", - what = base::I("Calling `layout_with_dh()` with positional or abbreviated arguments"), + what = base::I("Calling `layout_with_dh()` with positional, abbreviated or renamed arguments"), details = base::c( i = base::paste0("Detected call: layout_with_dh(", base::paste(base::c("graph", .arg_shown), collapse = ", "), ")"), i = base::paste0("Use instead: layout_with_dh(", base::paste(base::c("graph", base::paste0(.arg_names, " = ")), collapse = ", "), ")") @@ -1754,8 +1760,8 @@ layout_with_dh <- function( } # END GENERATED ARG_HANDLE - if (is.null(fineiter)) { - fineiter <- max(10, log2(vcount(graph))) + if (is.null(n_fine_iter)) { + n_fine_iter <- max(10, log2(vcount(graph))) } if (is.null(weight.edge.lengths)) { weight.edge.lengths <- edge_density(graph) / 10 @@ -1778,8 +1784,8 @@ layout_with_dh <- function( graph = graph, res = coords, use_seed = use.seed, - maxiter = maxiter, - fineiter = fineiter, + maxiter = n_iter, + fineiter = n_fine_iter, cool_fact = cool.fact, weight_node_dist = weight.node.dist, weight_border = weight.border, @@ -1814,7 +1820,7 @@ with_dh <- function(...) layout_spec(layout_with_dh, ...) #' @param dim Integer scalar, 2 or 3, the dimension of the layout. Two #' dimensional layouts are places on a plane, three dimensional ones in the 3d #' space. -#' @param niter Integer scalar, the number of iterations to perform. +#' @param n_iter Integer scalar, the number of iterations to perform. #' @param start.temp Real scalar, the start temperature. This is the maximum #' amount of movement alloved along one axis, within one step, for a vertex. #' Currently it is decreased linearly to zero during the iteration. The @@ -1882,7 +1888,7 @@ layout_with_fr <- function( ..., coords = NULL, dim = c(2, 3), - niter = 500, + n_iter = 500, start.temp = NULL, grid = c("auto", "grid", "nogrid"), weights = NULL, @@ -1915,7 +1921,7 @@ layout_with_fr <- function( base::list(env = base::environment(), recovered = base::c( if (!base::missing(coords)) base::c(coords = "coords"), if (!base::missing(dim)) base::c(dim = "dim"), - if (!base::missing(niter)) base::c(niter = "niter"), + if (!base::missing(niter)) base::c(n_iter = "niter"), if (!base::missing(start.temp)) base::c(start.temp = "start.temp"), if (!base::missing(grid)) base::c(grid = "grid"), if (!base::missing(weights)) base::c(weights = "weights"), @@ -1929,13 +1935,12 @@ layout_with_fr <- function( if (!base::missing(maxdelta)) base::c(maxdelta = "maxdelta"), if (!base::missing(area)) base::c(area = "area"), if (!base::missing(repulserad)) base::c(repulserad = "repulserad"), - if (!base::missing(maxiter)) base::c(niter = "maxiter") + if (!base::missing(maxiter)) base::c(n_iter = "maxiter") )) } .arg_given <- base::c( if (!base::missing(coords)) "coords", if (!base::missing(dim)) "dim", - if (!base::missing(niter)) "niter", if (!base::missing(start.temp)) "start.temp", if (!base::missing(grid)) "grid", if (!base::missing(weights)) "weights", @@ -1955,7 +1960,8 @@ layout_with_fr <- function( if (base::length(.arg_recovered) > 0L) { .arg_names <- base::names(.arg_recovered) .arg_conflict <- base::intersect(.arg_names, base::c( - if (!base::missing(niter)) "niter" + if (!base::missing(n_iter)) "n_iter", + if (!base::missing(n_iter)) "n_iter" )) if (base::length(.arg_conflict) > 0L) cli::cli_abort(base::c("Argument {.arg {(.arg_conflict)}} of {.fn layout_with_fr} was supplied more than once.", i = "Pass it exactly once, by its new name {.arg {(.arg_conflict)}}.")) 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())) @@ -1984,7 +1990,7 @@ layout_with_fr <- function( coords[] <- as.numeric(coords) dim <- igraph_match_arg(dim) - niter <- as.numeric(niter) + n_iter <- as.numeric(n_iter) start.temp <- as.numeric(start.temp) grid <- igraph_match_arg(grid) @@ -2035,7 +2041,7 @@ layout_with_fr <- function( Rx_igraph_layout_fruchterman_reingold, graph, coords, - niter, + n_iter, start.temp, weights, minx, @@ -2049,7 +2055,7 @@ layout_with_fr <- function( Rx_igraph_layout_fruchterman_reingold_3d, graph, coords, - niter, + n_iter, start.temp, weights, minx, @@ -2100,14 +2106,14 @@ layout.fruchterman.reingold <- function(..., params = list()) { #' @param coords Starting coordinates in a two or three column matrix, #' depending on the `dim` argument. #' Default: `NULL`. -#' @param maxiter The maximum number of iterations to perform. Updating a +#' @param max_iter The maximum number of iterations to perform. Updating a #' single vertex counts as an iteration. The default `NULL` uses 40 * n * n, #' where n is the number of vertices. The original paper suggests 4 * n * n, #' but this usually only works if the other parameters are set up carefully. #' @param temp.max The maximum allowed local temperature. The default `NULL` #' uses the number of vertices. #' @param temp.min The global temperature at which the algorithm terminates -#' (even before reaching `maxiter` iterations). A reasonable default is +#' (even before reaching `max_iter` iterations). A reasonable default is #' 1/10. #' @param temp.init Initial local temperature of all vertices. The default #' `NULL` uses the square root of the number of vertices. @@ -2133,7 +2139,7 @@ layout_with_gem <- function( graph, ..., coords = NULL, - maxiter = NULL, + max_iter = NULL, temp.max = NULL, temp.min = 0.1, temp.init = NULL @@ -2153,7 +2159,7 @@ layout_with_gem <- function( } base::list(env = base::environment(), recovered = base::c( if (!base::missing(coords)) base::c(coords = "coords"), - if (!base::missing(maxiter)) base::c(maxiter = "maxiter"), + if (!base::missing(maxiter)) base::c(max_iter = "maxiter"), if (!base::missing(temp.max)) base::c(temp.max = "temp.max"), if (!base::missing(temp.min)) base::c(temp.min = "temp.min"), if (!base::missing(temp.init)) base::c(temp.init = "temp.init") @@ -2161,7 +2167,6 @@ layout_with_gem <- function( } .arg_given <- base::c( if (!base::missing(coords)) "coords", - if (!base::missing(maxiter)) "maxiter", if (!base::missing(temp.max)) "temp.max", if (!base::missing(temp.min)) "temp.min", if (!base::missing(temp.init)) "temp.init" @@ -2170,6 +2175,10 @@ layout_with_gem <- function( .arg_recovered <- .arg_handle$recovered[!base::is.element(.arg_handle$recovered, .arg_given)] if (base::length(.arg_recovered) > 0L) { .arg_names <- base::names(.arg_recovered) + .arg_conflict <- base::intersect(.arg_names, base::c( + if (!base::missing(max_iter)) "max_iter" + )) + if (base::length(.arg_conflict) > 0L) cli::cli_abort(base::c("Argument {.arg {(.arg_conflict)}} of {.fn layout_with_gem} was supplied more than once.", i = "Pass it exactly once, by its new name {.arg {(.arg_conflict)}}.")) 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())) .arg_dots <- base::substitute(...()) .arg_tags <- base::as.character(base::names(.arg_dots)) @@ -2178,7 +2187,7 @@ layout_with_gem <- function( .arg_shown <- base::ifelse(base::is.na(.arg_tag_of), .arg_recovered, base::paste0(.arg_tag_of, " = ")) lifecycle::deprecate_soft( "3.0.0", - what = base::I("Calling `layout_with_gem()` with positional or abbreviated arguments"), + what = base::I("Calling `layout_with_gem()` with positional, abbreviated or renamed arguments"), details = base::c( i = base::paste0("Detected call: layout_with_gem(", base::paste(base::c("graph", .arg_shown), collapse = ", "), ")"), i = base::paste0("Use instead: layout_with_gem(", base::paste(base::c("graph", base::paste0(.arg_names, " = ")), collapse = ", "), ")") @@ -2188,8 +2197,8 @@ layout_with_gem <- function( } # END GENERATED ARG_HANDLE - if (is.null(maxiter)) { - maxiter <- 40 * vcount(graph)^2 + if (is.null(max_iter)) { + max_iter <- 40 * vcount(graph)^2 } if (is.null(temp.max)) { temp.max <- max(vcount(graph), 1) @@ -2209,7 +2218,7 @@ layout_with_gem <- function( graph = graph, res = coords, use_seed = use.seed, - maxiter = maxiter, + maxiter = max_iter, temp_max = temp.max, temp_min = temp.min, temp_init = temp.init @@ -2244,7 +2253,7 @@ with_gem <- function(...) layout_spec(layout_with_gem, ...) #' @param start If given, then it should be a matrix with two columns and one #' line for each vertex. This matrix will be used as starting positions for the #' algorithm. If not given, then a random starting matrix is used. -#' @param niter Integer scalar, the number of iterations to perform. Should be +#' @param n_iter Integer scalar, the number of iterations to perform. Should be #' a couple of hundred in general. If you have a large graph then you might #' want to only do a few iterations and then check the result. If it is not #' good enough you can feed it in again in the `start` argument. The @@ -2271,7 +2280,7 @@ layout_with_graphopt <- function( graph, ..., start = NULL, - niter = 500, + n_iter = 500, charge = 0.001, mass = 30, spring.length = 0, @@ -2293,7 +2302,7 @@ layout_with_graphopt <- function( } base::list(env = base::environment(), recovered = base::c( if (!base::missing(start)) base::c(start = "start"), - if (!base::missing(niter)) base::c(niter = "niter"), + if (!base::missing(niter)) base::c(n_iter = "niter"), if (!base::missing(charge)) base::c(charge = "charge"), if (!base::missing(mass)) base::c(mass = "mass"), if (!base::missing(spring.length)) base::c(spring.length = "spring.length"), @@ -2303,7 +2312,6 @@ layout_with_graphopt <- function( } .arg_given <- base::c( if (!base::missing(start)) "start", - if (!base::missing(niter)) "niter", if (!base::missing(charge)) "charge", if (!base::missing(mass)) "mass", if (!base::missing(spring.length)) "spring.length", @@ -2314,6 +2322,10 @@ layout_with_graphopt <- function( .arg_recovered <- .arg_handle$recovered[!base::is.element(.arg_handle$recovered, .arg_given)] if (base::length(.arg_recovered) > 0L) { .arg_names <- base::names(.arg_recovered) + .arg_conflict <- base::intersect(.arg_names, base::c( + if (!base::missing(n_iter)) "n_iter" + )) + if (base::length(.arg_conflict) > 0L) cli::cli_abort(base::c("Argument {.arg {(.arg_conflict)}} of {.fn layout_with_graphopt} was supplied more than once.", i = "Pass it exactly once, by its new name {.arg {(.arg_conflict)}}.")) 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())) .arg_dots <- base::substitute(...()) .arg_tags <- base::as.character(base::names(.arg_dots)) @@ -2322,7 +2334,7 @@ layout_with_graphopt <- function( .arg_shown <- base::ifelse(base::is.na(.arg_tag_of), .arg_recovered, base::paste0(.arg_tag_of, " = ")) lifecycle::deprecate_soft( "3.0.0", - what = base::I("Calling `layout_with_graphopt()` with positional or abbreviated arguments"), + what = base::I("Calling `layout_with_graphopt()` with positional, abbreviated or renamed arguments"), details = base::c( i = base::paste0("Detected call: layout_with_graphopt(", base::paste(base::c("graph", .arg_shown), collapse = ", "), ")"), i = base::paste0("Use instead: layout_with_graphopt(", base::paste(base::c("graph", base::paste0(.arg_names, " = ")), collapse = ", "), ")") @@ -2334,7 +2346,7 @@ layout_with_graphopt <- function( ensure_igraph(graph) start[] <- as.numeric(start) - niter <- as.double(niter) + n_iter <- as.double(n_iter) charge <- as.double(charge) mass <- as.double(mass) spring.length <- as.double(spring.length) @@ -2345,7 +2357,7 @@ layout_with_graphopt <- function( .Call( Rx_igraph_layout_graphopt, graph, - niter, + n_iter, charge, mass, spring.length, @@ -2381,12 +2393,12 @@ with_graphopt <- function(...) layout_spec(layout_with_graphopt, ...) #' @param dim Integer scalar, 2 or 3, the dimension of the layout. Two #' dimensional layouts are places on a plane, three dimensional ones in the 3d #' space. -#' @param maxiter The maximum number of iterations to perform. The algorithm +#' @param max_iter The maximum number of iterations to perform. The algorithm #' might terminate earlier, see the `epsilon` argument. The default `NULL` #' uses `50 * vcount(graph)`. #' @param epsilon Numeric scalar, the algorithm terminates, if the maximal #' delta is less than this. (See the reference below for what delta means.) If -#' you set this to zero, then the function always performs `maxiter` +#' you set this to zero, then the function always performs `max_iter` #' iterations. #' @param kkconst Numeric scalar, the Kamada-Kawai vertex attraction constant. #' The default `NULL` uses the number of vertices. @@ -2432,7 +2444,7 @@ layout_with_kk <- function( ..., coords = NULL, dim = c(2, 3), - maxiter = NULL, + max_iter = NULL, epsilon = 0.0, kkconst = NULL, weights = NULL, @@ -2451,7 +2463,7 @@ layout_with_kk <- function( # BEGIN GENERATED ARG_HANDLE: layout_with_kk, do not edit, see tools/generate-migrations.R # fmt: skip if (...length() > 0L) { - .arg_ambiguous <- base::intersect(base::names(base::substitute(...())), base::c("c", "co", "coo", "m", "ma", "max", "mi", "min", "s")) + .arg_ambiguous <- base::intersect(base::names(base::substitute(...())), base::c("m", "ma", "max", "c", "co", "coo", "mi", "min", "s")) if (base::length(.arg_ambiguous) > 0L) cli::cli_abort("Argument {.arg {(.arg_ambiguous[[1L]])}} matches multiple arguments of {.fn layout_with_kk}.") # Pre-3.0.0 signature: layout_with_kk(graph, coords, dim, maxiter, epsilon, kkconst, weights, minx, maxx, miny, maxy, minz, maxz, niter, sigma, initemp, coolexp, start) .old_signature <- function(coords, dim, maxiter, epsilon, kkconst, weights, minx, maxx, miny, maxy, minz, maxz, niter, sigma, initemp, coolexp, start, ...) { @@ -2464,7 +2476,7 @@ layout_with_kk <- function( base::list(env = base::environment(), recovered = base::c( if (!base::missing(coords)) base::c(coords = "coords"), if (!base::missing(dim)) base::c(dim = "dim"), - if (!base::missing(maxiter)) base::c(maxiter = "maxiter"), + if (!base::missing(maxiter)) base::c(max_iter = "maxiter"), if (!base::missing(epsilon)) base::c(epsilon = "epsilon"), if (!base::missing(kkconst)) base::c(kkconst = "kkconst"), if (!base::missing(weights)) base::c(weights = "weights"), @@ -2484,7 +2496,6 @@ layout_with_kk <- function( .arg_given <- base::c( if (!base::missing(coords)) "coords", if (!base::missing(dim)) "dim", - if (!base::missing(maxiter)) "maxiter", if (!base::missing(epsilon)) "epsilon", if (!base::missing(kkconst)) "kkconst", if (!base::missing(weights)) "weights", @@ -2504,6 +2515,10 @@ layout_with_kk <- function( .arg_recovered <- .arg_handle$recovered[!base::is.element(.arg_handle$recovered, .arg_given)] if (base::length(.arg_recovered) > 0L) { .arg_names <- base::names(.arg_recovered) + .arg_conflict <- base::intersect(.arg_names, base::c( + if (!base::missing(max_iter)) "max_iter" + )) + if (base::length(.arg_conflict) > 0L) cli::cli_abort(base::c("Argument {.arg {(.arg_conflict)}} of {.fn layout_with_kk} was supplied more than once.", i = "Pass it exactly once, by its new name {.arg {(.arg_conflict)}}.")) 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())) .arg_dots <- base::substitute(...()) .arg_tags <- base::as.character(base::names(.arg_dots)) @@ -2512,7 +2527,7 @@ layout_with_kk <- function( .arg_shown <- base::ifelse(base::is.na(.arg_tag_of), .arg_recovered, base::paste0(.arg_tag_of, " = ")) lifecycle::deprecate_soft( "3.0.0", - what = base::I("Calling `layout_with_kk()` with positional or abbreviated arguments"), + what = base::I("Calling `layout_with_kk()` with positional, abbreviated or renamed arguments"), details = base::c( i = base::paste0("Detected call: layout_with_kk(", base::paste(base::c("graph", .arg_shown), collapse = ", "), ")"), i = base::paste0("Use instead: layout_with_kk(", base::paste(base::c("graph", base::paste0(.arg_names, " = ")), collapse = ", "), ")") @@ -2522,8 +2537,8 @@ layout_with_kk <- function( } # END GENERATED ARG_HANDLE - if (is.null(maxiter)) { - maxiter <- 50 * vcount(graph) + if (is.null(max_iter)) { + max_iter <- 50 * vcount(graph) } if (is.null(kkconst)) { kkconst <- max(vcount(graph), 1) @@ -2549,7 +2564,7 @@ layout_with_kk <- function( coords[] <- as.numeric(coords) dim <- igraph_match_arg(dim) - maxiter <- as.numeric(maxiter) + max_iter <- as.numeric(max_iter) epsilon <- as.numeric(epsilon) kkconst <- as.numeric(kkconst) if (is.null(weights) && "weight" %in% edge_attr_names(graph)) { @@ -2599,7 +2614,7 @@ layout_with_kk <- function( Rx_igraph_layout_kamada_kawai, graph, coords, - maxiter, + max_iter, epsilon, kkconst, weights, @@ -2613,7 +2628,7 @@ layout_with_kk <- function( Rx_igraph_layout_kamada_kawai_3d, graph, coords, - maxiter, + max_iter, epsilon, kkconst, weights, @@ -2665,7 +2680,7 @@ layout.kamada.kawai <- function(..., params = list()) { #' #' @param graph The input graph #' @inheritParams rlang::args_dots_empty -#' @param maxiter The maximum number of iterations to perform (150). +#' @param max_iter The maximum number of iterations to perform (150). #' @param maxdelta The maximum change for a vertex during an iteration. The #' default `NULL` uses the number of vertices. #' @param area The area of the surface on which the vertices are placed. The @@ -2689,7 +2704,7 @@ layout.kamada.kawai <- function(..., params = list()) { layout_with_lgl <- function( graph, ..., - maxiter = 150, + max_iter = 150, maxdelta = NULL, area = NULL, coolexp = 1.5, @@ -2711,7 +2726,7 @@ layout_with_lgl <- function( cli::cli_abort(base::c("Unexpected argument passed to {.fn layout_with_lgl}: {.arg {(.arg_extra)}}.", i = "Arguments after {.arg ...} must be spelled out in full."), call = base::parent.frame()) } base::list(env = base::environment(), recovered = base::c( - if (!base::missing(maxiter)) base::c(maxiter = "maxiter"), + if (!base::missing(maxiter)) base::c(max_iter = "maxiter"), if (!base::missing(maxdelta)) base::c(maxdelta = "maxdelta"), if (!base::missing(area)) base::c(area = "area"), if (!base::missing(coolexp)) base::c(coolexp = "coolexp"), @@ -2721,7 +2736,6 @@ layout_with_lgl <- function( )) } .arg_given <- base::c( - if (!base::missing(maxiter)) "maxiter", if (!base::missing(maxdelta)) "maxdelta", if (!base::missing(area)) "area", if (!base::missing(coolexp)) "coolexp", @@ -2733,6 +2747,10 @@ layout_with_lgl <- function( .arg_recovered <- .arg_handle$recovered[!base::is.element(.arg_handle$recovered, .arg_given)] if (base::length(.arg_recovered) > 0L) { .arg_names <- base::names(.arg_recovered) + .arg_conflict <- base::intersect(.arg_names, base::c( + if (!base::missing(max_iter)) "max_iter" + )) + if (base::length(.arg_conflict) > 0L) cli::cli_abort(base::c("Argument {.arg {(.arg_conflict)}} of {.fn layout_with_lgl} was supplied more than once.", i = "Pass it exactly once, by its new name {.arg {(.arg_conflict)}}.")) 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())) .arg_dots <- base::substitute(...()) .arg_tags <- base::as.character(base::names(.arg_dots)) @@ -2741,7 +2759,7 @@ layout_with_lgl <- function( .arg_shown <- base::ifelse(base::is.na(.arg_tag_of), .arg_recovered, base::paste0(.arg_tag_of, " = ")) lifecycle::deprecate_soft( "3.0.0", - what = base::I("Calling `layout_with_lgl()` with positional or abbreviated arguments"), + what = base::I("Calling `layout_with_lgl()` with positional, abbreviated or renamed arguments"), details = base::c( i = base::paste0("Detected call: layout_with_lgl(", base::paste(base::c("graph", .arg_shown), collapse = ", "), ")"), i = base::paste0("Use instead: layout_with_lgl(", base::paste(base::c("graph", base::paste0(.arg_names, " = ")), collapse = ", "), ")") @@ -2775,7 +2793,7 @@ layout_with_lgl <- function( .Call( Rx_igraph_layout_lgl, graph, - as.double(maxiter), + as.double(max_iter), as.double(maxdelta), as.double(area), as.double(coolexp), @@ -2910,7 +2928,7 @@ with_mds <- function(...) layout_spec(layout_with_mds, ...) #' @param hgap Real scalar, the minimum horizontal gap between vertices in the #' same layer. #' @param vgap Real scalar, the distance between layers. -#' @param maxiter Integer scalar, the maximum number of iterations in the +#' @param max_iter Integer scalar, the maximum number of iterations in the #' crossing minimization stage. 100 is a reasonable default; if you feel that #' you have too many edge crossings, increase this. #' @param weights Optional edge weight vector. If `NULL`, then the @@ -3096,7 +3114,7 @@ layout_with_sugiyama <- function( layers = NULL, hgap = 1, vgap = 1, - maxiter = 100, + max_iter = 100, weights = NULL, attributes = c("default", "all", "none") ) { @@ -3115,7 +3133,7 @@ layout_with_sugiyama <- function( if (!base::missing(layers)) base::c(layers = "layers"), if (!base::missing(hgap)) base::c(hgap = "hgap"), if (!base::missing(vgap)) base::c(vgap = "vgap"), - if (!base::missing(maxiter)) base::c(maxiter = "maxiter"), + if (!base::missing(maxiter)) base::c(max_iter = "maxiter"), if (!base::missing(weights)) base::c(weights = "weights"), if (!base::missing(attributes)) base::c(attributes = "attributes") )) @@ -3124,7 +3142,6 @@ layout_with_sugiyama <- function( if (!base::missing(layers)) "layers", if (!base::missing(hgap)) "hgap", if (!base::missing(vgap)) "vgap", - if (!base::missing(maxiter)) "maxiter", if (!base::missing(weights)) "weights", if (!base::missing(attributes)) "attributes" ) @@ -3132,6 +3149,10 @@ layout_with_sugiyama <- function( .arg_recovered <- .arg_handle$recovered[!base::is.element(.arg_handle$recovered, .arg_given)] if (base::length(.arg_recovered) > 0L) { .arg_names <- base::names(.arg_recovered) + .arg_conflict <- base::intersect(.arg_names, base::c( + if (!base::missing(max_iter)) "max_iter" + )) + if (base::length(.arg_conflict) > 0L) cli::cli_abort(base::c("Argument {.arg {(.arg_conflict)}} of {.fn layout_with_sugiyama} was supplied more than once.", i = "Pass it exactly once, by its new name {.arg {(.arg_conflict)}}.")) 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())) .arg_dots <- base::substitute(...()) .arg_tags <- base::as.character(base::names(.arg_dots)) @@ -3140,7 +3161,7 @@ layout_with_sugiyama <- function( .arg_shown <- base::ifelse(base::is.na(.arg_tag_of), .arg_recovered, base::paste0(.arg_tag_of, " = ")) lifecycle::deprecate_soft( "3.0.0", - what = base::I("Calling `layout_with_sugiyama()` with positional or abbreviated arguments"), + what = base::I("Calling `layout_with_sugiyama()` with positional, abbreviated or renamed arguments"), details = base::c( i = base::paste0("Detected call: layout_with_sugiyama(", base::paste(base::c("graph", .arg_shown), collapse = ", "), ")"), i = base::paste0("Use instead: layout_with_sugiyama(", base::paste(base::c("graph", base::paste0(.arg_names, " = ")), collapse = ", "), ")") @@ -3157,7 +3178,7 @@ layout_with_sugiyama <- function( layers = layers, hgap = hgap, vgap = vgap, - maxiter = maxiter, + maxiter = max_iter, weights = weights ) diff --git a/R/rewire.R b/R/rewire.R index 274824e054..3afce59b3f 100644 --- a/R/rewire.R +++ b/R/rewire.R @@ -37,7 +37,7 @@ #' 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))) +#' print_all(rewire(g, with = keeping_degseq(n_iter = vcount(g) * 10))) rewire <- function(graph, with) { if (!is(with, "igraph_rewiring_method")) { cli::cli_abort( @@ -60,7 +60,8 @@ rewire <- function(graph, with) { #' edges. #' #' @param loops Whether to allow destroying and creating loop edges. -#' @param niter Number of rewiring trials to perform. +#' @param n_iter Number of rewiring trials to perform. +#' @param niter `r lifecycle::badge("deprecated")` Use `n_iter` instead. #' #' @author Tamas Nepusz \email{ntamas@@gmail.com} and Gabor Csardi #' \email{csardi.gabor@@gmail.com} @@ -71,13 +72,28 @@ rewire <- function(graph, with) { #' @examples #' g <- make_ring(10) #' g %>% -#' rewire(keeping_degseq(niter = 20)) %>% +#' rewire(keeping_degseq(n_iter = 20)) %>% #' degree() -#' print_all(rewire(g, with = keeping_degseq(niter = vcount(g) * 10))) -keeping_degseq <- function(loops = FALSE, niter = 100) { +#' print_all(rewire(g, with = keeping_degseq(n_iter = vcount(g) * 10))) +keeping_degseq <- function(loops = FALSE, n_iter = 100, niter = deprecated()) { + if (lifecycle::is_present(niter)) { + if (!missing(n_iter)) { + cli::cli_abort(c( + "Argument {.arg n_iter} of {.fn keeping_degseq} was supplied more than once.", + i = "It was also supplied via its legacy name {.arg niter}." + )) + } + lifecycle::deprecate_soft( + "3.0.0", + "keeping_degseq(niter = )", + "keeping_degseq(n_iter = )" + ) + n_iter <- niter + } + method <- list( fun = rewire_keeping_degseq, - args = list(loops = loops, niter = niter) + args = list(loops = loops, niter = n_iter) ) add_class(method, "igraph_rewiring_method") } diff --git a/R/sgm.R b/R/sgm.R index 29e6cf9345..ba004f7f25 100644 --- a/R/sgm.R +++ b/R/sgm.R @@ -65,7 +65,8 @@ solve_LSAP <- function(x, maximum = FALSE) { #' matched. #' @param start a numeric matrix, the permutation matrix estimate is #' initialized with `start` -#' @param iteration The number of iterations for the Frank-Wolfe algorithm +#' @param max_iter The number of iterations for the Frank-Wolfe algorithm +#' @param iteration `r lifecycle::badge("deprecated")` Use `max_iter` instead. #' @return A numeric matrix which is the permutation matrix that determines the #' bijection between the graphs of `A` and `B` #' @author Vince Lyzinski @@ -91,7 +92,22 @@ solve_LSAP <- function(x, maximum = FALSE) { #' P #' @family sgm #' @export -match_vertices <- function(A, B, m, start, iteration) { +match_vertices <- function(A, B, m, start, max_iter, iteration = deprecated()) { + if (lifecycle::is_present(iteration)) { + if (!missing(max_iter)) { + cli::cli_abort(c( + "Argument {.arg max_iter} of {.fn match_vertices} was supplied more than once.", + i = "It was also supplied via its legacy name {.arg iteration}." + )) + } + lifecycle::deprecate_soft( + "3.0.0", + "match_vertices(iteration = )", + "match_vertices(max_iter = )" + ) + max_iter <- iteration + } + ## Seeds are assumed to be vertices 1:m in both graphs totv <- ncol(A) n <- totv - m @@ -109,7 +125,7 @@ match_vertices <- function(A, B, m, start, iteration) { } A22 <- A[(m + 1):(m + n), (m + 1):(m + n)] B22 <- B[(m + 1):(m + n), (m + 1):(m + n)] - patience <- iteration + patience <- max_iter tol <- 1 P <- start toggle <- 1 diff --git a/R/tkplot.R b/R/tkplot.R index 1c5281579c..e1c0070a37 100644 --- a/R/tkplot.R +++ b/R/tkplot.R @@ -311,7 +311,7 @@ tkplot <- function(graph, canvas.width = 450, canvas.height = 450, ...) { name = "Fruchterman-Reingold", f = layout_with_fr, params = list( - niter = list( + n_iter = list( name = "Number of iterations", type = "numeric", default = 500 @@ -330,7 +330,7 @@ tkplot <- function(graph, canvas.width = 450, canvas.height = 450, ...) { name = "Kamada-Kawai", f = layout_with_kk, params = list( - maxiter = list( + max_iter = list( name = "Maximum number of iterations", type = "expression", default = expression(50 * vcount(.tkplot.g)) @@ -364,12 +364,12 @@ tkplot <- function(graph, canvas.width = 450, canvas.height = 450, ...) { name = "Davidson-Harel", f = layout_with_dh, params = list( - maxiter = list( + n_iter = list( name = "Maximum iterations", type = "numeric", default = 10 ), - fineiter = list( + n_fine_iter = list( name = "Fine-tuning iterations", type = "expression", default = expression(max(10, log2(vcount(.tkplot.g)))) diff --git a/man/cluster_leiden.Rd b/man/cluster_leiden.Rd index 376105aed3..1096891484 100644 --- a/man/cluster_leiden.Rd +++ b/man/cluster_leiden.Rd @@ -14,7 +14,7 @@ cluster_leiden( resolution_parameter = deprecated(), beta = 0.01, initial_membership = NULL, - n_iterations = 2, + n_iter = 2, vertex_weights = NULL ) } @@ -48,7 +48,7 @@ This affects only the refinement step of the algorithm.} will try to improve this provided membership. If no argument is provided, the aglorithm simply starts from the singleton partition.} -\item{n_iterations}{the number of iterations to iterate the Leiden +\item{n_iter}{the number of iterations to iterate the Leiden algorithm. Each iteration may improve the partition further.} \item{vertex_weights}{the vertex weights used in the Leiden algorithm. diff --git a/man/graphlet_basis.Rd b/man/graphlet_basis.Rd index 7edde89970..c134675b8d 100644 --- a/man/graphlet_basis.Rd +++ b/man/graphlet_basis.Rd @@ -8,9 +8,9 @@ \usage{ graphlet_basis(graph, ..., weights = NULL) -graphlet_proj(graph, ..., weights = NULL, cliques, niter = 1000, Mu = NULL) +graphlet_proj(graph, ..., weights = NULL, cliques, n_iter = 1000, Mu = NULL) -graphlets(graph, ..., weights = NULL, niter = 1000) +graphlets(graph, ..., weights = NULL, n_iter = 1000) } \arguments{ \item{graph}{The input graph, edge directions are ignored. Only simple graph @@ -25,7 +25,7 @@ attribute is used.} \item{cliques}{A list of vertex IDs, the graphlet basis to use for the projection.} -\item{niter}{Integer scalar, the number of iterations to perform.} +\item{n_iter}{Integer scalar, the number of iterations to perform.} \item{Mu}{Starting weights for the projection. The default \code{NULL} uses a weight of one for each clique.} @@ -99,7 +99,7 @@ par(mar = c(1, 1, 1, 1)) plot(g, layout = co) ## Calculate graphlets -gl <- graphlets(g, niter = 1000) +gl <- graphlets(g, n_iter = 1000) ## Plot graphlets for (i in seq_along(gl$cliques)) { diff --git a/man/graphlets.project.Rd b/man/graphlets.project.Rd index a17a596c4b..b6ae3c73e0 100644 --- a/man/graphlets.project.Rd +++ b/man/graphlets.project.Rd @@ -23,8 +23,6 @@ attribute is used.} \item{cliques}{A list of vertex IDs, the graphlet basis to use for the projection.} -\item{niter}{Integer scalar, the number of iterations to perform.} - \item{Mu}{Starting weights for the projection. The default \code{NULL} uses a weight of one for each clique.} } diff --git a/man/keeping_degseq.Rd b/man/keeping_degseq.Rd index 225e14316d..c5c8a985da 100644 --- a/man/keeping_degseq.Rd +++ b/man/keeping_degseq.Rd @@ -4,12 +4,14 @@ \alias{keeping_degseq} \title{Graph rewiring while preserving the degree distribution} \usage{ -keeping_degseq(loops = FALSE, niter = 100) +keeping_degseq(loops = FALSE, n_iter = 100, niter = deprecated()) } \arguments{ \item{loops}{Whether to allow destroying and creating loop edges.} -\item{niter}{Number of rewiring trials to perform.} +\item{n_iter}{Number of rewiring trials to perform.} + +\item{niter}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} Use \code{n_iter} instead.} } \description{ This function can be used together with \code{\link[=rewire]{rewire()}} to @@ -25,9 +27,9 @@ edges. \examples{ g <- make_ring(10) g \%>\% - rewire(keeping_degseq(niter = 20)) \%>\% + rewire(keeping_degseq(n_iter = 20)) \%>\% degree() -print_all(rewire(g, with = keeping_degseq(niter = vcount(g) * 10))) +print_all(rewire(g, with = keeping_degseq(n_iter = vcount(g) * 10))) } \seealso{ \code{\link[=sample_degseq]{sample_degseq()}} diff --git a/man/layout.bipartite.Rd b/man/layout.bipartite.Rd index a1d9c50972..ffa2e73e3e 100644 --- a/man/layout.bipartite.Rd +++ b/man/layout.bipartite.Rd @@ -19,10 +19,6 @@ used.} same layer.} \item{vgap}{Real scalar, the distance between the two layers.} - -\item{maxiter}{Integer scalar, the maximum number of iterations in the -crossing minimization stage. 100 is a reasonable default; if you feel that -you have too many edge crossings, increase this.} } \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/layout.davidson.harel.Rd b/man/layout.davidson.harel.Rd index 2df57ce460..a9396d33be 100644 --- a/man/layout.davidson.harel.Rd +++ b/man/layout.davidson.harel.Rd @@ -24,11 +24,6 @@ layout.davidson.harel( is not \code{NULL} then it should be an appropriate matrix of starting coordinates.} -\item{maxiter}{Number of iterations to perform in the first phase.} - -\item{fineiter}{Number of iterations in the fine tuning phase. The -default \code{NULL} uses \code{max(10, log2(vcount(graph)))}.} - \item{cool.fact}{Cooling factor.} \item{weight.node.dist}{Weight for the node-node distances component of the diff --git a/man/layout.gem.Rd b/man/layout.gem.Rd index 9046cfc733..e7cefde301 100644 --- a/man/layout.gem.Rd +++ b/man/layout.gem.Rd @@ -20,16 +20,11 @@ layout.gem( depending on the \code{dim} argument. Default: \code{NULL}.} -\item{maxiter}{The maximum number of iterations to perform. Updating a -single vertex counts as an iteration. The default \code{NULL} uses 40 * n * n, -where n is the number of vertices. The original paper suggests 4 * n * n, -but this usually only works if the other parameters are set up carefully.} - \item{temp.max}{The maximum allowed local temperature. The default \code{NULL} uses the number of vertices.} \item{temp.min}{The global temperature at which the algorithm terminates -(even before reaching \code{maxiter} iterations). A reasonable default is +(even before reaching \code{max_iter} iterations). A reasonable default is 1/10.} \item{temp.init}{Initial local temperature of all vertices. The default diff --git a/man/layout.graphopt.Rd b/man/layout.graphopt.Rd index 6ae8c116bd..f107b27e7d 100644 --- a/man/layout.graphopt.Rd +++ b/man/layout.graphopt.Rd @@ -22,12 +22,6 @@ layout.graphopt( line for each vertex. This matrix will be used as starting positions for the algorithm. If not given, then a random starting matrix is used.} -\item{niter}{Integer scalar, the number of iterations to perform. Should be -a couple of hundred in general. If you have a large graph then you might -want to only do a few iterations and then check the result. If it is not -good enough you can feed it in again in the \code{start} argument. The -default value is 500.} - \item{charge}{The charge of the vertices, used to calculate electric repulsion. The default is 0.001.} diff --git a/man/layout.sugiyama.Rd b/man/layout.sugiyama.Rd index 3bf2aa46b0..c310c7727a 100644 --- a/man/layout.sugiyama.Rd +++ b/man/layout.sugiyama.Rd @@ -26,10 +26,6 @@ same layer.} \item{vgap}{Real scalar, the distance between layers.} -\item{maxiter}{Integer scalar, the maximum number of iterations in the -crossing minimization stage. 100 is a reasonable default; if you feel that -you have too many edge crossings, increase this.} - \item{weights}{Optional edge weight vector. If \code{NULL}, then the 'weight' edge attribute is used, if there is one. Supply \code{NA} here and igraph ignores the edge weights. These are used only if the graph diff --git a/man/layout_as_bipartite.Rd b/man/layout_as_bipartite.Rd index 83158b0359..9953eba8d8 100644 --- a/man/layout_as_bipartite.Rd +++ b/man/layout_as_bipartite.Rd @@ -10,7 +10,7 @@ layout_as_bipartite( ..., hgap = 1, vgap = 1, - maxiter = 100 + max_iter = 100 ) } \arguments{ @@ -29,7 +29,7 @@ same layer.} \item{vgap}{Real scalar, the distance between the two layers.} -\item{maxiter}{Integer scalar, the maximum number of iterations in the +\item{max_iter}{Integer scalar, the maximum number of iterations in the crossing minimization stage. 100 is a reasonable default; if you feel that you have too many edge crossings, increase this.} } diff --git a/man/layout_with_dh.Rd b/man/layout_with_dh.Rd index 3b7f56da3c..a8d9e3702d 100644 --- a/man/layout_with_dh.Rd +++ b/man/layout_with_dh.Rd @@ -8,8 +8,8 @@ layout_with_dh( graph, ..., coords = NULL, - maxiter = 10, - fineiter = NULL, + n_iter = 10, + n_fine_iter = NULL, cool.fact = 0.75, weight.node.dist = 1, weight.border = 0, @@ -27,9 +27,9 @@ layout_with_dh( is not \code{NULL} then it should be an appropriate matrix of starting coordinates.} -\item{maxiter}{Number of iterations to perform in the first phase.} +\item{n_iter}{Number of iterations to perform in the first phase.} -\item{fineiter}{Number of iterations in the fine tuning phase. The +\item{n_fine_iter}{Number of iterations in the fine tuning phase. The default \code{NULL} uses \code{max(10, log2(vcount(graph)))}.} \item{cool.fact}{Cooling factor.} diff --git a/man/layout_with_fr.Rd b/man/layout_with_fr.Rd index 4e3283b438..4735cde72f 100644 --- a/man/layout_with_fr.Rd +++ b/man/layout_with_fr.Rd @@ -9,7 +9,7 @@ layout_with_fr( ..., coords = NULL, dim = c(2, 3), - niter = 500, + n_iter = 500, start.temp = NULL, grid = c("auto", "grid", "nogrid"), weights = NULL, @@ -38,7 +38,7 @@ coordinates.} dimensional layouts are places on a plane, three dimensional ones in the 3d space.} -\item{niter}{Integer scalar, the number of iterations to perform.} +\item{n_iter}{Integer scalar, the number of iterations to perform.} \item{start.temp}{Real scalar, the start temperature. This is the maximum amount of movement alloved along one axis, within one step, for a vertex. diff --git a/man/layout_with_gem.Rd b/man/layout_with_gem.Rd index 9fb74e2a0f..620861c36d 100644 --- a/man/layout_with_gem.Rd +++ b/man/layout_with_gem.Rd @@ -8,7 +8,7 @@ layout_with_gem( graph, ..., coords = NULL, - maxiter = NULL, + max_iter = NULL, temp.max = NULL, temp.min = 0.1, temp.init = NULL @@ -23,7 +23,7 @@ layout_with_gem( depending on the \code{dim} argument. Default: \code{NULL}.} -\item{maxiter}{The maximum number of iterations to perform. Updating a +\item{max_iter}{The maximum number of iterations to perform. Updating a single vertex counts as an iteration. The default \code{NULL} uses 40 * n * n, where n is the number of vertices. The original paper suggests 4 * n * n, but this usually only works if the other parameters are set up carefully.} @@ -32,7 +32,7 @@ but this usually only works if the other parameters are set up carefully.} uses the number of vertices.} \item{temp.min}{The global temperature at which the algorithm terminates -(even before reaching \code{maxiter} iterations). A reasonable default is +(even before reaching \code{max_iter} iterations). A reasonable default is 1/10.} \item{temp.init}{Initial local temperature of all vertices. The default diff --git a/man/layout_with_graphopt.Rd b/man/layout_with_graphopt.Rd index 0d56e5ff1f..9baea2ef59 100644 --- a/man/layout_with_graphopt.Rd +++ b/man/layout_with_graphopt.Rd @@ -8,7 +8,7 @@ layout_with_graphopt( graph, ..., start = NULL, - niter = 500, + n_iter = 500, charge = 0.001, mass = 30, spring.length = 0, @@ -25,7 +25,7 @@ layout_with_graphopt( line for each vertex. This matrix will be used as starting positions for the algorithm. If not given, then a random starting matrix is used.} -\item{niter}{Integer scalar, the number of iterations to perform. Should be +\item{n_iter}{Integer scalar, the number of iterations to perform. Should be a couple of hundred in general. If you have a large graph then you might want to only do a few iterations and then check the result. If it is not good enough you can feed it in again in the \code{start} argument. The diff --git a/man/layout_with_kk.Rd b/man/layout_with_kk.Rd index 20d7c09bf9..b84c70c4f5 100644 --- a/man/layout_with_kk.Rd +++ b/man/layout_with_kk.Rd @@ -9,7 +9,7 @@ layout_with_kk( ..., coords = NULL, dim = c(2, 3), - maxiter = NULL, + max_iter = NULL, epsilon = 0, kkconst = NULL, weights = NULL, @@ -39,13 +39,13 @@ Default: \code{NULL}.} dimensional layouts are places on a plane, three dimensional ones in the 3d space.} -\item{maxiter}{The maximum number of iterations to perform. The algorithm +\item{max_iter}{The maximum number of iterations to perform. The algorithm might terminate earlier, see the \code{epsilon} argument. The default \code{NULL} uses \code{50 * vcount(graph)}.} \item{epsilon}{Numeric scalar, the algorithm terminates, if the maximal delta is less than this. (See the reference below for what delta means.) If -you set this to zero, then the function always performs \code{maxiter} +you set this to zero, then the function always performs \code{max_iter} iterations.} \item{kkconst}{Numeric scalar, the Kamada-Kawai vertex attraction constant. diff --git a/man/layout_with_lgl.Rd b/man/layout_with_lgl.Rd index 3a41057a0e..4faf04ccf6 100644 --- a/man/layout_with_lgl.Rd +++ b/man/layout_with_lgl.Rd @@ -7,7 +7,7 @@ layout_with_lgl( graph, ..., - maxiter = 150, + max_iter = 150, maxdelta = NULL, area = NULL, coolexp = 1.5, @@ -21,7 +21,7 @@ layout_with_lgl( \item{...}{These dots are for future extensions and must be empty.} -\item{maxiter}{The maximum number of iterations to perform (150).} +\item{max_iter}{The maximum number of iterations to perform (150).} \item{maxdelta}{The maximum change for a vertex during an iteration. The default \code{NULL} uses the number of vertices.} diff --git a/man/layout_with_sugiyama.Rd b/man/layout_with_sugiyama.Rd index 11e4ecf083..4199801d81 100644 --- a/man/layout_with_sugiyama.Rd +++ b/man/layout_with_sugiyama.Rd @@ -10,7 +10,7 @@ layout_with_sugiyama( layers = NULL, hgap = 1, vgap = 1, - maxiter = 100, + max_iter = 100, weights = NULL, attributes = c("default", "all", "none") ) @@ -29,7 +29,7 @@ same layer.} \item{vgap}{Real scalar, the distance between layers.} -\item{maxiter}{Integer scalar, the maximum number of iterations in the +\item{max_iter}{Integer scalar, the maximum number of iterations in the crossing minimization stage. 100 is a reasonable default; if you feel that you have too many edge crossings, increase this.} diff --git a/man/match_vertices.Rd b/man/match_vertices.Rd index f65f79ae54..eb7a46933d 100644 --- a/man/match_vertices.Rd +++ b/man/match_vertices.Rd @@ -5,7 +5,7 @@ \alias{seeded.graph.match} \title{Match Graphs given a seeding of vertex correspondences} \usage{ -match_vertices(A, B, m, start, iteration) +match_vertices(A, B, m, start, max_iter, iteration = deprecated()) } \arguments{ \item{A}{a numeric matrix, the adjacency matrix of the first graph} @@ -18,7 +18,9 @@ matched.} \item{start}{a numeric matrix, the permutation matrix estimate is initialized with \code{start}} -\item{iteration}{The number of iterations for the Frank-Wolfe algorithm} +\item{max_iter}{The number of iterations for the Frank-Wolfe algorithm} + +\item{iteration}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} Use \code{max_iter} instead.} } \value{ A numeric matrix which is the permutation matrix that determines the diff --git a/man/rewire.Rd b/man/rewire.Rd index 773aa11d69..c8bb7d561a 100644 --- a/man/rewire.Rd +++ b/man/rewire.Rd @@ -23,7 +23,7 @@ g <- make_ring(10) 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))) +print_all(rewire(g, with = keeping_degseq(n_iter = vcount(g) * 10))) } \seealso{ Other rewiring functions: diff --git a/tests/testthat/_snaps/community.md b/tests/testthat/_snaps/community.md index ec0ab0c0d7..f44d129656 100644 --- a/tests/testthat/_snaps/community.md +++ b/tests/testthat/_snaps/community.md @@ -13,7 +13,7 @@ res <- cluster_leiden(g, "modularity", NULL, 1.5) Condition Warning: - Calling `cluster_leiden()` with positional or abbreviated arguments was deprecated in igraph 3.0.0. + Calling `cluster_leiden()` with positional, abbreviated or renamed arguments was deprecated in igraph 3.0.0. i Detected call: cluster_leiden(graph, objective_function, weights, resolution_parameter) i Use instead: cluster_leiden(graph, objective_function, weights = , resolution_parameter = ) Warning: diff --git a/tests/testthat/_snaps/layout.md b/tests/testthat/_snaps/layout.md index 599ec67c5e..92f6e6625c 100644 --- a/tests/testthat/_snaps/layout.md +++ b/tests/testthat/_snaps/layout.md @@ -1,7 +1,7 @@ # layout_with_fr() deprecated argument Code - l <- layout_with_fr(g, niter = 50, start.temp = sqrt(10) / 10, coolexp = 1, + l <- layout_with_fr(g, n_iter = 50, start.temp = sqrt(10) / 10, coolexp = 1, maxdelta = 1, area = 1, repulserad = 1) Condition Error: @@ -10,7 +10,7 @@ # layout_with_kk() deprecated arguments Code - l <- layout_with_kk(g, maxiter = 50, coords = layout_in_circle(g), niter = 1, + l <- layout_with_kk(g, max_iter = 50, coords = layout_in_circle(g), niter = 1, sigma = 1, initemp = 1, coolexp = 1) Condition Error: @@ -32,3 +32,13 @@ Error in `layout_randomly()`: ! `dim` must be one of "2" or "3", not "4". +# legacy iteration argument names are deprecated but still work + + Code + res <- layout_with_fr(g, coords = coords, niter = 20) + Condition + Warning: + Calling `layout_with_fr()` with positional, abbreviated or renamed arguments was deprecated in igraph 3.0.0. + i Detected call: layout_with_fr(graph, niter = ) + i Use instead: layout_with_fr(graph, n_iter = ) + diff --git a/tests/testthat/_snaps/rewire.md b/tests/testthat/_snaps/rewire.md new file mode 100644 index 0000000000..c886e2a4ce --- /dev/null +++ b/tests/testthat/_snaps/rewire.md @@ -0,0 +1,18 @@ +# keeping_degseq(niter = ) is deprecated but still works + + Code + res <- keeping_degseq(niter = 20) + Condition + Warning: + The `niter` argument of `keeping_degseq()` is deprecated as of igraph 3.0.0. + i Please use the `n_iter` argument instead. + +--- + + Code + keeping_degseq(n_iter = 20, niter = 10) + Condition + Error in `keeping_degseq()`: + ! Argument `n_iter` of `keeping_degseq()` was supplied more than once. + i It was also supplied via its legacy name `niter`. + diff --git a/tests/testthat/test-community.R b/tests/testthat/test-community.R index c0d0acfb1e..7fadd3c1e3 100644 --- a/tests/testthat/test-community.R +++ b/tests/testthat/test-community.R @@ -1089,6 +1089,20 @@ test_that("modularity_matrix() covers migrated tail args and positional recovery }) }) +test_that("cluster_leiden(n_iterations = ) is deprecated but still works", { + rlang::local_options(lifecycle_verbosity = "warning") + g <- make_graph("Zachary") + igraph_local_seed(42) + lifecycle::expect_deprecated( + res <- cluster_leiden(g, "modularity", n_iterations = 3) + ) + igraph_local_seed(42) + expect_equal( + membership(res), + membership(cluster_leiden(g, "modularity", n_iter = 3)) + ) +}) + test_that("cluster_infomap() code length on the karate graph", { # Pins the vendored Infomap implementation. igraph_local_seed(42) diff --git a/tests/testthat/test-constant-defaults.R b/tests/testthat/test-constant-defaults.R index e09d12e6b9..b5cd4ef03a 100644 --- a/tests/testthat/test-constant-defaults.R +++ b/tests/testthat/test-constant-defaults.R @@ -73,7 +73,7 @@ test_that("NULL non-selector defaults of round-2 functions resolve in the body", expect_identical_graphs(g1, g2) igraph_local_seed(1) - l1 <- layout_with_kk(g, kkconst = NULL, maxiter = NULL) + l1 <- layout_with_kk(g, kkconst = NULL, max_iter = NULL) igraph_local_seed(1) l2 <- layout_with_kk(g) expect_identical(l1, l2) diff --git a/tests/testthat/test-glet.R b/tests/testthat/test-glet.R index af039389da..88013c3dbb 100644 --- a/tests/testthat/test-glet.R +++ b/tests/testthat/test-glet.R @@ -126,7 +126,7 @@ test_that("graphlet_proj() covers all tail arguments", { g, weights = E(g)$weight, cliques = cl, - niter = 100, + n_iter = 100, Mu = rep(2, length(cl)) ) expect_type(res, "double") @@ -148,7 +148,7 @@ test_that("graphlets() covers all tail arguments", { w <- rep(1, ecount(g)) # Uniform weights collapse the basis to the two maximal cliques. - res <- graphlets(g, weights = w, niter = 50) + res <- graphlets(g, weights = w, n_iter = 50) expect_named(res, c("cliques", "Mu")) expect_length(res$cliques, 2) expect_length(res$Mu, length(res$cliques)) @@ -159,3 +159,15 @@ test_that("graphlets() covers all tail arguments", { ) expect_identical(res_legacy, graphlets(g, weights = w)) }) + +test_that("graphlets(niter = ) and graphlet_proj(niter = ) are deprecated but still work", { + rlang::local_options(lifecycle_verbosity = "warning") + g <- make_graphlet_graph() + cl <- graphlet_basis(g)$cliques + lifecycle::expect_deprecated(res <- graphlets(g, niter = 50)) + expect_equal(res, graphlets(g, n_iter = 50)) + lifecycle::expect_deprecated( + res <- graphlet_proj(g, cliques = cl, niter = 50) + ) + expect_equal(res, graphlet_proj(g, cliques = cl, n_iter = 50)) +}) diff --git a/tests/testthat/test-layout.R b/tests/testthat/test-layout.R index ddbdd24900..927d4f0b69 100644 --- a/tests/testthat/test-layout.R +++ b/tests/testthat/test-layout.R @@ -3,13 +3,13 @@ test_that("layout_with_fr() works", { igraph_with_seed(42, { g <- make_ring(10) - l <- layout_with_fr(g, niter = 50, start.temp = sqrt(10) / 10) + l <- layout_with_fr(g, n_iter = 50, start.temp = sqrt(10) / 10) }) expect_equal(sum(l), 4.57228, tolerance = 0.1) igraph_with_seed(42, { g <- make_star(30) - l <- layout_with_fr(g, niter = 500, dim = 3, start.temp = 20) + l <- layout_with_fr(g, n_iter = 500, dim = 3, start.temp = 20) }) expect_equal(sum(l), -170.9312, tolerance = 0.1) }) @@ -20,7 +20,7 @@ test_that("layout_with_fr() deprecated argument", { expect_snapshot_igraph_error({ l <- layout_with_fr( g, - niter = 50, + n_iter = 50, start.temp = sqrt(10) / 10, coolexp = 1, maxdelta = 1, @@ -197,20 +197,20 @@ test_that("Kamada-Kawai layout generator works", { } g <- make_ring(10) - l <- layout_with_kk(g, maxiter = 50, coords = layout_in_circle(g)) + l <- layout_with_kk(g, max_iter = 50, coords = layout_in_circle(g)) expect_true(looks_circular(l)) g <- make_star(12) - l <- layout_with_kk(g, maxiter = 500, coords = layout_in_circle(g)) + l <- layout_with_kk(g, max_iter = 500, coords = layout_in_circle(g)) expect_true(looks_circular(l[-1, ])) g <- make_ring(10) E(g)$weight <- rep(1:2, length.out = ecount(g)) - l <- layout_with_kk(g, maxiter = 500, coords = layout_in_circle(g)) + l <- layout_with_kk(g, max_iter = 500, coords = layout_in_circle(g)) expect_true(looks_circular(l, check_dists = FALSE)) g <- make_star(30) - l <- layout_with_kk(g, maxiter = 5000, dim = 3) + l <- layout_with_kk(g, max_iter = 5000, dim = 3) expect_true(looks_circular(l[-1, ], check_dists = FALSE, eps = 1e-2)) }) @@ -219,7 +219,7 @@ test_that("layout_with_kk() deprecated arguments", { expect_snapshot_igraph_error({ l <- layout_with_kk( g, - maxiter = 50, + max_iter = 50, coords = layout_in_circle(g), niter = 1, sigma = 1, @@ -522,7 +522,7 @@ test_that("layout_as_bipartite() covers tail args and recovers positional calls" g <- make_full_bipartite_graph(3, 2) # All tail arguments by name. - l <- layout_as_bipartite(g, V(g)$type, hgap = 3, vgap = 2, maxiter = 50) + l <- layout_as_bipartite(g, V(g)$type, hgap = 3, vgap = 2, max_iter = 50) expect_equal(dim(l), c(5, 2)) # The two vertex types end up on rows vgap apart. expect_equal(sort(unique(l[, 2])), c(0, 2)) @@ -645,8 +645,8 @@ test_that("layout_with_dh() covers tail args and recovers positional calls", { l <- layout_with_dh( g, coords = coords, - maxiter = 5, - fineiter = 5, + n_iter = 5, + n_fine_iter = 5, cool.fact = 0.5, weight.node.dist = 2, weight.border = 0.1, @@ -663,7 +663,7 @@ test_that("layout_with_dh() covers tail args and recovers positional calls", { lifecycle::expect_deprecated(res <- layout_with_dh(g, coords, maxiter = 5)) }) igraph_with_seed(1, { - ref <- layout_with_dh(g, coords = coords, maxiter = 5) + ref <- layout_with_dh(g, coords = coords, n_iter = 5) }) expect_identical(res, ref) }) @@ -724,7 +724,7 @@ test_that("layout_with_fr() covers the remaining tail args and recovery", { l <- layout_with_fr( g, coords = coords, - niter = 20, + n_iter = 20, grid = "nogrid", weights = rep(0.5, ecount(g)), minx = rep(-3, 10), @@ -742,7 +742,7 @@ test_that("layout_with_fr() covers the remaining tail args and recovery", { l3 <- layout_with_fr( g, dim = 3, - niter = 20, + n_iter = 20, minz = rep(-2, 10), maxz = rep(2, 10) ) @@ -755,7 +755,7 @@ test_that("layout_with_fr() covers the remaining tail args and recovery", { lifecycle::expect_deprecated(res <- layout_with_fr(g, coords, niter = 20)) }) igraph_with_seed(1, { - ref <- layout_with_fr(g, coords = coords, niter = 20) + ref <- layout_with_fr(g, coords = coords, n_iter = 20) }) expect_identical(res, ref) }) @@ -769,7 +769,7 @@ test_that("layout_with_gem() covers tail args and recovers positional calls", { l <- layout_with_gem( g, coords = coords, - maxiter = 100, + max_iter = 100, temp.max = 5, temp.min = 0.5, temp.init = 2 @@ -797,7 +797,7 @@ test_that("layout_with_graphopt() covers tail args and recovers positional calls l <- layout_with_graphopt( g, start = start, - niter = 50, + n_iter = 50, charge = 0.01, mass = 10, spring.length = 1, @@ -827,7 +827,7 @@ test_that("layout_with_kk() covers the remaining tail args and recovery", { l <- layout_with_kk( g, coords = coords, - maxiter = 50, + max_iter = 50, epsilon = 1e-3, kkconst = 5, weights = rep(2, ecount(g)), @@ -845,7 +845,7 @@ test_that("layout_with_kk() covers the remaining tail args and recovery", { l3 <- layout_with_kk( g, dim = 3, - maxiter = 50, + max_iter = 50, minz = rep(0, 10), maxz = rep(1, 10) ) @@ -855,7 +855,7 @@ test_that("layout_with_kk() covers the remaining tail args and recovery", { # The legacy positional call recovers coords and warns. lifecycle::expect_deprecated(res <- layout_with_kk(g, coords, maxiter = 50)) - expect_identical(res, layout_with_kk(g, coords = coords, maxiter = 50)) + expect_identical(res, layout_with_kk(g, coords = coords, max_iter = 50)) }) test_that("layout_with_lgl() covers tail args and recovers positional calls", { @@ -865,7 +865,7 @@ test_that("layout_with_lgl() covers tail args and recovers positional calls", { igraph_with_seed(42, { l <- layout_with_lgl( g, - maxiter = 50, + max_iter = 50, maxdelta = 5, area = 64, coolexp = 1.2, @@ -882,7 +882,7 @@ test_that("layout_with_lgl() covers tail args and recovers positional calls", { lifecycle::expect_deprecated(res <- layout_with_lgl(g, 50)) }) igraph_with_seed(1, { - ref <- layout_with_lgl(g, maxiter = 50) + ref <- layout_with_lgl(g, max_iter = 50) }) expect_identical(res, ref) }) @@ -897,7 +897,7 @@ test_that("layout_with_sugiyama() covers tail args and recovers positional calls layers = c(1, 2, 3, 4), hgap = 2, vgap = 2, - maxiter = 50, + max_iter = 50, weights = rep(1, ecount(g)), attributes = "all" ) @@ -956,6 +956,67 @@ test_that("norm_coords() recovers positional calls", { expect_equal(range(res[, 1]), c(0, 1)) }) +test_that("legacy iteration argument names are deprecated but still work", { + rlang::local_options(lifecycle_verbosity = "warning") + g <- make_ring(10) + coords <- layout_in_circle(g) + + igraph_local_seed(42) + expect_snapshot_igraph(res <- layout_with_fr(g, coords = coords, niter = 20)) + igraph_local_seed(42) + expect_equal(res, layout_with_fr(g, coords = coords, n_iter = 20)) + # `maxiter` was an alias of `niter`, it now also maps to `n_iter` + igraph_local_seed(42) + lifecycle::expect_deprecated( + res <- layout_with_fr(g, coords = coords, maxiter = 20) + ) + igraph_local_seed(42) + expect_equal(res, layout_with_fr(g, coords = coords, n_iter = 20)) + + lifecycle::expect_deprecated( + res <- layout_with_kk(g, coords = coords, maxiter = 50) + ) + expect_equal(res, layout_with_kk(g, coords = coords, max_iter = 50)) + + igraph_local_seed(42) + lifecycle::expect_deprecated( + res <- layout_with_dh(g, coords = coords, maxiter = 5, fineiter = 5) + ) + igraph_local_seed(42) + expect_equal( + res, + layout_with_dh(g, coords = coords, n_iter = 5, n_fine_iter = 5) + ) + + igraph_local_seed(42) + lifecycle::expect_deprecated(res <- layout_with_graphopt(g, niter = 50)) + igraph_local_seed(42) + expect_equal(res, layout_with_graphopt(g, n_iter = 50)) + + igraph_local_seed(42) + lifecycle::expect_deprecated(res <- layout_with_gem(g, maxiter = 50)) + igraph_local_seed(42) + expect_equal(res, layout_with_gem(g, max_iter = 50)) + + igraph_local_seed(42) + lifecycle::expect_deprecated(res <- layout_with_lgl(g, maxiter = 50)) + igraph_local_seed(42) + expect_equal(res, layout_with_lgl(g, max_iter = 50)) + + bip <- make_bipartite_graph(c(0, 1, 0, 1), c(1, 2, 2, 3, 3, 4)) + lifecycle::expect_deprecated(res <- layout_as_bipartite(bip, maxiter = 10)) + expect_equal(res, layout_as_bipartite(bip, max_iter = 10)) + + tree <- make_tree(7) + lifecycle::expect_deprecated( + res <- layout_with_sugiyama(tree, maxiter = 10) + ) + ref <- layout_with_sugiyama(tree, max_iter = 10) + expect_equal(res$layout, ref$layout) + expect_equal(res$layout.dummy, ref$layout.dummy) + expect_identical_graphs(res$extd_graph, ref$extd_graph) +}) + test_that("layout_with_gem() random stream for a fixed seed", { # Pins the random numbers the C core draws for this layout. igraph_local_seed(42) diff --git a/tests/testthat/test-rewire.R b/tests/testthat/test-rewire.R index 4382025e8c..8a9a60a50c 100644 --- a/tests/testthat/test-rewire.R +++ b/tests/testthat/test-rewire.R @@ -52,3 +52,10 @@ test_that("each_edge() recovers legacy positional arguments", { ) expect_identical(res, each_edge(0.3, loops = TRUE)) }) + +test_that("keeping_degseq(niter = ) is deprecated but still works", { + rlang::local_options(lifecycle_verbosity = "warning") + expect_snapshot_igraph(res <- keeping_degseq(niter = 20)) + expect_equal(res, keeping_degseq(n_iter = 20)) + expect_snapshot_igraph_error(keeping_degseq(n_iter = 20, niter = 10)) +}) diff --git a/tests/testthat/test-sgm.R b/tests/testthat/test-sgm.R index 64363db1b9..0dfc53db74 100644 --- a/tests/testthat/test-sgm.R +++ b/tests/testthat/test-sgm.R @@ -12,7 +12,7 @@ test_that("SGM works", { g2[], m = nos, start = matrix(1 / (vc - nos), vc - nos, vc - nos), - iteration = 20 + max_iter = 20 ) expect_equal(c(1:nos, P$corr[, 2]), randperm) @@ -37,7 +37,7 @@ test_that("SGM works", { g2[], m = nos, start = matrix(1 / (vc - nos), vc - nos, vc - nos), - iteration = 20 + max_iter = 20 ) expect_equal(P$corr[, 2], perm[(nos + 1):vc]) @@ -54,3 +54,17 @@ test_that("LSAP does not change input matrix", { expect_equal(x, matrix(c(5, 1, 4, 3, 5, 2, 2, 4, 4), nrow = 3)) }) + +test_that("match_vertices(iteration = ) is deprecated but still works", { + rlang::local_options(lifecycle_verbosity = "warning") + igraph_local_seed(42) + g1 <- sample_gnp(10, 0.5) + start <- matrix(1 / 7, 7, 7) + lifecycle::expect_deprecated( + res <- match_vertices(g1[], g1[], m = 3, start = start, iteration = 5) + ) + expect_equal( + res, + match_vertices(g1[], g1[], m = 3, start = start, max_iter = 5) + ) +}) diff --git a/tools/migrations/community.R b/tools/migrations/community.R index 78f59efba4..43f5b3952c 100644 --- a/tools/migrations/community.R +++ b/tools/migrations/community.R @@ -68,7 +68,7 @@ migrations <- list( resolution_parameter, beta, initial_membership, - n_iterations, + n_iterations = n_iter, vertex_weights ) {}, new = function( @@ -80,7 +80,7 @@ migrations <- list( resolution_parameter = deprecated(), beta = 0.01, initial_membership = NULL, - n_iterations = 2, + n_iter = 2, vertex_weights = NULL ) {}, when = "3.0.0" diff --git a/tools/migrations/layout.R b/tools/migrations/layout.R index fd76e22495..b29ada90b1 100644 --- a/tools/migrations/layout.R +++ b/tools/migrations/layout.R @@ -4,14 +4,14 @@ migrations <- list( layout_as_bipartite = list( - old = function(graph, types, hgap, vgap, maxiter) {}, + old = function(graph, types, hgap, vgap, maxiter = max_iter) {}, new = function( graph, types = NULL, ..., hgap = 1, vgap = 1, - maxiter = 100 + max_iter = 100 ) {}, when = "3.0.0" ), @@ -67,8 +67,8 @@ migrations <- list( old = function( graph, coords, - maxiter, - fineiter, + maxiter = n_iter, + fineiter = n_fine_iter, cool.fact, weight.node.dist, weight.border, @@ -80,8 +80,8 @@ migrations <- list( graph, ..., coords = NULL, - maxiter = 10, - fineiter = NULL, + n_iter = 10, + n_fine_iter = NULL, cool.fact = 0.75, weight.node.dist = 1.0, weight.border = 0.0, @@ -111,7 +111,7 @@ migrations <- list( graph, coords, dim, - niter, + niter = n_iter, start.temp, grid, weights, @@ -125,14 +125,14 @@ migrations <- list( maxdelta, area, repulserad, - maxiter = niter + maxiter = n_iter ) {}, new = function( graph, ..., coords = NULL, dim = c(2, 3), - niter = 500, + n_iter = 500, start.temp = NULL, grid = c("auto", "grid", "nogrid"), weights = NULL, @@ -151,12 +151,19 @@ migrations <- list( ), layout_with_gem = list( - old = function(graph, coords, maxiter, temp.max, temp.min, temp.init) {}, + old = function( + graph, + coords, + maxiter = max_iter, + temp.max, + temp.min, + temp.init + ) {}, new = function( graph, ..., coords = NULL, - maxiter = NULL, + max_iter = NULL, temp.max = NULL, temp.min = 0.1, temp.init = NULL @@ -168,7 +175,7 @@ migrations <- list( old = function( graph, start, - niter, + niter = n_iter, charge, mass, spring.length, @@ -179,7 +186,7 @@ migrations <- list( graph, ..., start = NULL, - niter = 500, + n_iter = 500, charge = 0.001, mass = 30, spring.length = 0, @@ -194,7 +201,7 @@ migrations <- list( graph, coords, dim, - maxiter, + maxiter = max_iter, epsilon, kkconst, weights, @@ -215,7 +222,7 @@ migrations <- list( ..., coords = NULL, dim = c(2, 3), - maxiter = NULL, + max_iter = NULL, epsilon = 0.0, kkconst = NULL, weights = NULL, @@ -237,7 +244,7 @@ migrations <- list( layout_with_lgl = list( old = function( graph, - maxiter, + maxiter = max_iter, maxdelta, area, coolexp, @@ -248,7 +255,7 @@ migrations <- list( new = function( graph, ..., - maxiter = 150, + max_iter = 150, maxdelta = NULL, area = NULL, coolexp = 1.5, @@ -260,14 +267,22 @@ migrations <- list( ), layout_with_sugiyama = list( - old = function(graph, layers, hgap, vgap, maxiter, weights, attributes) {}, + old = function( + graph, + layers, + hgap, + vgap, + maxiter = max_iter, + weights, + attributes + ) {}, new = function( graph, ..., layers = NULL, hgap = 1, vgap = 1, - maxiter = 100, + max_iter = 100, weights = NULL, attributes = c("default", "all", "none") ) {}, diff --git a/tools/migrations/motifs-graphlets.R b/tools/migrations/motifs-graphlets.R index 7bf83db155..856bf28471 100644 --- a/tools/migrations/motifs-graphlets.R +++ b/tools/migrations/motifs-graphlets.R @@ -14,25 +14,25 @@ migrations <- list( ), graphlet_proj = list( - old = function(graph, weights, cliques, niter, Mu) {}, + old = function(graph, weights, cliques, niter = n_iter, Mu) {}, new = function( graph, ..., weights = NULL, cliques, - niter = 1000, + n_iter = 1000, Mu = NULL ) {}, when = "3.0.0" ), graphlets = list( - old = function(graph, weights, niter) {}, + old = function(graph, weights, niter = n_iter) {}, new = function( graph, ..., weights = NULL, - niter = 1000 + n_iter = 1000 ) {}, when = "3.0.0" ),