diff --git a/DESCRIPTION b/DESCRIPTION index 296ca9d47f1..235616d800c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -33,6 +33,7 @@ Imports: cli, graphics, grDevices, + lifecycle, magrittr, Matrix, pkgconfig (>= 2.0.0), diff --git a/NAMESPACE b/NAMESPACE index 80077dbd720..5f0db0a4b38 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -489,7 +489,6 @@ export(hrg_tree) export(hub.score) export(hub_score) export(identical_graphs) -export(igraph.arpack.default) export(igraph.console) export(igraph.drl.coarsen) export(igraph.drl.coarsest) diff --git a/R/aaa-auto.R b/R/aaa-auto.R index 71cebbcfd39..236298df065 100644 --- a/R/aaa-auto.R +++ b/R/aaa-auto.R @@ -371,7 +371,7 @@ personalized_pagerank_impl <- function(graph, algo=c("prpack", "arpack"), vids=V if (algo == 0L) { options <- list(niter=1000, eps=0.001) } else if (algo == 1L) { - options <- arpack_defaults + options <- arpack_defaults() } else { options <- NULL } @@ -549,7 +549,7 @@ count_multiple_impl <- function(graph, eids=E(graph)) { res } -eigenvector_centrality_impl <- function(graph, directed=FALSE, scale=TRUE, weights=NULL, options=arpack_defaults) { +eigenvector_centrality_impl <- function(graph, directed=FALSE, scale=TRUE, weights=NULL, options=arpack_defaults()) { # Argument checks ensure_igraph(graph) directed <- as.logical(directed) @@ -562,7 +562,7 @@ eigenvector_centrality_impl <- function(graph, directed=FALSE, scale=TRUE, weigh } else { weights <- NULL } - options.tmp <- arpack_defaults; options.tmp[ names(options) ] <- options ; options <- options.tmp + options <- modify_list(arpack_defaults(), options) on.exit( .Call(R_igraph_finalizer) ) # Function call @@ -573,7 +573,7 @@ eigenvector_centrality_impl <- function(graph, directed=FALSE, scale=TRUE, weigh res } -hub_score_impl <- function(graph, scale=TRUE, weights=NULL, options=arpack_defaults) { +hub_score_impl <- function(graph, scale=TRUE, weights=NULL, options=arpack_defaults()) { # Argument checks ensure_igraph(graph) scale <- as.logical(scale) @@ -585,7 +585,7 @@ hub_score_impl <- function(graph, scale=TRUE, weights=NULL, options=arpack_defau } else { weights <- NULL } - options.tmp <- arpack_defaults; options.tmp[ names(options) ] <- options ; options <- options.tmp + options.tmp <- arpack_defaults(); options.tmp[ names(options) ] <- options ; options <- options.tmp on.exit( .Call(R_igraph_finalizer) ) # Function call @@ -596,7 +596,7 @@ hub_score_impl <- function(graph, scale=TRUE, weights=NULL, options=arpack_defau res } -authority_score_impl <- function(graph, scale=TRUE, weights=NULL, options=arpack_defaults) { +authority_score_impl <- function(graph, scale=TRUE, weights=NULL, options=arpack_defaults()) { # Argument checks ensure_igraph(graph) scale <- as.logical(scale) @@ -608,7 +608,7 @@ authority_score_impl <- function(graph, scale=TRUE, weights=NULL, options=arpack } else { weights <- NULL } - options.tmp <- arpack_defaults; options.tmp[ names(options) ] <- options ; options <- options.tmp + options.tmp <- arpack_defaults(); options.tmp[ names(options) ] <- options ; options <- options.tmp on.exit( .Call(R_igraph_finalizer) ) # Function call @@ -772,12 +772,12 @@ centralization_closeness_tmax_impl <- function(graph=NULL, nodes=0, mode=c("out" res } -centralization_eigenvector_centrality_impl <- function(graph, directed=FALSE, scale=TRUE, options=arpack_defaults, normalized=TRUE) { +centralization_eigenvector_centrality_impl <- function(graph, directed=FALSE, scale=TRUE, options=arpack_defaults(), normalized=TRUE) { # Argument checks ensure_igraph(graph) directed <- as.logical(directed) scale <- as.logical(scale) - options.tmp <- arpack_defaults; options.tmp[ names(options) ] <- options ; options <- options.tmp + options.tmp <- arpack_defaults(); options.tmp[ names(options) ] <- options ; options <- options.tmp normalized <- as.logical(normalized) on.exit( .Call(R_igraph_finalizer) ) @@ -2013,7 +2013,7 @@ scg_norm_eps_impl <- function(V, groups, mtype=c("symmetric", "laplacian", "stoc res } -adjacency_spectral_embedding_impl <- function(graph, no, weights=NULL, which=c("lm", "la", "sa"), scaled=TRUE, cvec=graph.strength(graph, weights=weights)/(vcount(graph)-1), options=igraph.arpack.default) { +adjacency_spectral_embedding_impl <- function(graph, no, weights=NULL, which=c("lm", "la", "sa"), scaled=TRUE, cvec=graph.strength(graph, weights=weights)/(vcount(graph)-1), options=arpack_defaults()) { # Argument checks ensure_igraph(graph) no <- as.integer(no) @@ -2028,7 +2028,7 @@ adjacency_spectral_embedding_impl <- function(graph, no, weights=NULL, which=c(" which <- switch(igraph.match.arg(which), "lm"=0L, "la"=2L, "sa"=3L) scaled <- as.logical(scaled) cvec <- as.numeric(cvec) - options.tmp <- arpack_defaults; options.tmp[ names(options) ] <- options ; options <- options.tmp + options.tmp <- arpack_defaults(); options.tmp[ names(options) ] <- options ; options <- options.tmp on.exit( .Call(R_igraph_finalizer) ) # Function call @@ -2037,7 +2037,7 @@ adjacency_spectral_embedding_impl <- function(graph, no, weights=NULL, which=c(" res } -laplacian_spectral_embedding_impl <- function(graph, no, weights=NULL, which=c("lm", "la", "sa"), type=c("default", "D-A", "DAD", "I-DAD", "OAP"), scaled=TRUE, options=igraph.arpack.default) { +laplacian_spectral_embedding_impl <- function(graph, no, weights=NULL, which=c("lm", "la", "sa"), type=c("default", "D-A", "DAD", "I-DAD", "OAP"), scaled=TRUE, options=arpack_defaults()) { # Argument checks ensure_igraph(graph) no <- as.integer(no) @@ -2055,7 +2055,7 @@ laplacian_spectral_embedding_impl <- function(graph, no, weights=NULL, which=c(" "da"=0L, "d-a"=0L, "idad"=1L, "i-dad"=1L, "dad"=2L, "oap"=3L) scaled <- as.logical(scaled) - options.tmp <- arpack_defaults; options.tmp[ names(options) ] <- options ; options <- options.tmp + options.tmp <- arpack_defaults(); options.tmp[ names(options) ] <- options ; options <- options.tmp on.exit( .Call(R_igraph_finalizer) ) # Function call @@ -2064,7 +2064,7 @@ laplacian_spectral_embedding_impl <- function(graph, no, weights=NULL, which=c(" res } -eigen_adjacency_impl <- function(graph, algorithm=c("arpack", "auto", "lapack", "comp_auto", "comp_lapack", "comp_arpack"), which=list(), options=arpack_defaults) { +eigen_adjacency_impl <- function(graph, algorithm=c("arpack", "auto", "lapack", "comp_auto", "comp_lapack", "comp_arpack"), which=list(), options=arpack_defaults()) { # Argument checks ensure_igraph(graph) algorithm <- switch(igraph.match.arg(algorithm), "auto"=0, "lapack"=1, @@ -2072,7 +2072,7 @@ eigen_adjacency_impl <- function(graph, algorithm=c("arpack", "auto", "lapack", "comp_arpack"=5) which.tmp <- eigen_defaults(); which.tmp[ names(which) ] <- which ; which <- which.tmp - options.tmp <- arpack_defaults; options.tmp[ names(options) ] <- options ; options <- options.tmp + options.tmp <- arpack_defaults(); options.tmp[ names(options) ] <- options ; options <- options.tmp on.exit( .Call(R_igraph_finalizer) ) # Function call diff --git a/R/centrality.R b/R/centrality.R index bec35ff9f14..bdfb1503cb3 100644 --- a/R/centrality.R +++ b/R/centrality.R @@ -302,11 +302,13 @@ estimate_closeness <- function(graph, vids = V(graph), mode = c("out", "in", "al #' @rdname arpack #' @family arpack #' @export -arpack_defaults <- list( - bmat = "I", n = 0, which = "XX", nev = 1, tol = 0.0, - ncv = 3, ldv = 0, ishift = 1, maxiter = 3000, nb = 1, - mode = 1, start = 0, sigma = 0.0, sigmai = 0.0 -) +arpack_defaults <- function() { + list( + bmat = "I", n = 0, which = "XX", nev = 1, tol = 0.0, + ncv = 3, ldv = 0, ishift = 1, maxiter = 3000, nb = 1, + mode = 1, start = 0, sigma = 0.0, sigmai = 0.0 + ) +} #' ARPACK eigenvector calculation #' @@ -415,8 +417,7 @@ arpack_defaults <- list( #' re-orthogonalization.} } } Please see the ARPACK documentation for #' additional details. #' -#' @aliases arpack arpack-options igraph.arpack.default arpack.unpack.complex -#' arpack_defaults +#' @aliases arpack arpack-options arpack.unpack.complex arpack_defaults #' @param func The function to perform the matrix-vector multiplication. ARPACK #' requires to perform these by the user. The function gets the vector \eqn{x} #' as the first argument, and it should return \eqn{Ax}, where \eqn{A} is the @@ -496,8 +497,21 @@ arpack_defaults <- list( #' } #' @family arpack #' @export -arpack <- function(func, extra = NULL, sym = FALSE, options = arpack_defaults, +arpack <- function(func, extra = NULL, sym = FALSE, options = arpack_defaults(), env = parent.frame(), complex = !sym) { + + eval_try <- rlang::eval_tidy(options) + options_value <- rlang::call_args(rlang::current_call())[["options"]] + if (is(eval_try, "function") && as.character(options_value) == "arpack_defaults") { + lifecycle::deprecate_soft( + "1.5.0", + I("arpack_defaults"), + "arpack_defaults()", + details = c("So the function arpack_defaults(), not an object called code arpack_defaults.") + ) + options <- arpack_defaults() + } + if (!is.list(options) || (is.null(names(options)) && length(options) != 0)) { stop("options must be a named list") @@ -505,18 +519,16 @@ arpack <- function(func, extra = NULL, sym = FALSE, options = arpack_defaults, if (any(names(options) == "")) { stop("all options must be named") } - if (any(!names(options) %in% names(arpack_defaults))) { + if (any(!names(options) %in% names(arpack_defaults()))) { stop( "unkown ARPACK option(s): ", - paste(setdiff(names(options), names(arpack_defaults)), + paste(setdiff(names(options), names(arpack_defaults())), collapse = ", " ) ) } - options.tmp <- arpack_defaults - options.tmp[names(options)] <- options - options <- options.tmp + options <- modify_list(arpack_defaults(), options) if (sym && complex) { complex <- FALSE diff --git a/R/community.R b/R/community.R index 021920036e9..9bde7b1c4d2 100644 --- a/R/community.R +++ b/R/community.R @@ -1655,7 +1655,7 @@ igraph.i.levc.arp <- function(externalP, externalE) { #' cluster_leading_eigen <- function(graph, steps = -1, weights = NULL, start = NULL, - options = arpack_defaults, + options = arpack_defaults(), callback = NULL, extra = NULL, env = parent.frame()) { # Argument checks @@ -1673,9 +1673,7 @@ cluster_leading_eigen <- function(graph, steps = -1, weights = NULL, if (!is.null(start)) { start <- as.numeric(start) - 1 } - options.tmp <- arpack_defaults - options.tmp[names(options)] <- options - options <- options.tmp + options <- modify_list(arpack_defaults(), options) on.exit(.Call(R_igraph_finalizer)) # Function call diff --git a/R/embedding.R b/R/embedding.R index 5e402ab64c1..809ec0ce57f 100644 --- a/R/embedding.R +++ b/R/embedding.R @@ -65,7 +65,7 @@ #' graph. This vector is added to the diagonal of the adjacency matrix. #' @param options A named list containing the parameters for the SVD #' computation algorithm in ARPACK. By default, the list of values is assigned -#' the values given by [igraph.arpack.default]. +#' the values given by [arpack_defaults()]. #' @return A list containing with entries: \item{X}{Estimated latent positions, #' an `n` times `no` matrix, `n` is the number of vertices.} #' \item{Y}{`NULL` for undirected graphs, the second half of the latent @@ -203,7 +203,7 @@ dim_select <- dim_select_impl #' returned instead of \eqn{X} and \eqn{Y}. #' @param options A named list containing the parameters for the SVD #' computation algorithm in ARPACK. By default, the list of values is assigned -#' the values given by [igraph.arpack.default]. +#' the values given by [arpack_defaults()]. #' @return A list containing with entries: \item{X}{Estimated latent positions, #' an `n` times `no` matrix, `n` is the number of vertices.} #' \item{Y}{`NULL` for undirected graphs, the second half of the latent diff --git a/R/layout.R b/R/layout.R index 8466096d393..b70a231cac6 100644 --- a/R/layout.R +++ b/R/layout.R @@ -1517,7 +1517,7 @@ layout.lgl <- function(..., params = list()) { #' l <- layout_with_mds(g) #' plot(g, layout = l, vertex.label = NA, vertex.size = 3) layout_with_mds <- function(graph, dist = NULL, dim = 2, - options = arpack_defaults) { + options = arpack_defaults()) { # Argument checks ensure_igraph(graph) if (!is.null(dist)) dist <- structure(as.double(dist), dim = dim(dist)) diff --git a/R/layout_drl.R b/R/layout_drl.R index f3ab659caf5..525539257fd 100644 --- a/R/layout_drl.R +++ b/R/layout_drl.R @@ -100,9 +100,7 @@ layout_with_drl <- function(graph, use.seed = FALSE, use.seed <- as.logical(use.seed) seed <- as.matrix(seed) - options.tmp <- drl_defaults$default - options.tmp[names(options)] <- options - options <- options.tmp + options <- modify_list(drl_defaults$default, options) if (is.null(weights) && "weight" %in% edge_attr_names(graph)) { weights <- E(graph)$weight diff --git a/R/utils.R b/R/utils.R index b8b6920bb77..305e063dd33 100644 --- a/R/utils.R +++ b/R/utils.R @@ -97,3 +97,12 @@ chr <- as.character drop_null <- function(x) { x[!sapply(x, is.null)] } + +# from https://github.com/r-lib/pkgdown/blob/c354aa7e5ea1f9936692494c28c89e5bdd31fc68/R/utils.R#L109 +modify_list <- function(x, y) { + if (is.null(y)) { + return(x) + } + + utils::modifyList(x, y) +} diff --git a/R/zzz-deprecate.R b/R/zzz-deprecate.R index 98ef6e532cc..f2f8b63b96b 100644 --- a/R/zzz-deprecate.R +++ b/R/zzz-deprecate.R @@ -317,8 +317,6 @@ deprecated("hrg.predict", predict_edges) #' @export hub.score deprecated("hub.score", hub_score) -#' @export igraph.arpack.default -deprecated("igraph.arpack.default", arpack_defaults) #' @export igraph.console deprecated("igraph.console", console) #' @export igraph.sample diff --git a/man/arpack.Rd b/man/arpack.Rd index b03d3d76471..604a431331a 100644 --- a/man/arpack.Rd +++ b/man/arpack.Rd @@ -1,24 +1,19 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/centrality.R -\docType{data} \name{arpack_defaults} \alias{arpack_defaults} \alias{arpack} \alias{arpack-options} -\alias{igraph.arpack.default} \alias{arpack.unpack.complex} \title{ARPACK eigenvector calculation} -\format{ -An object of class \code{list} of length 14. -} \usage{ -arpack_defaults +arpack_defaults() arpack( func, extra = NULL, sym = FALSE, - options = arpack_defaults, + options = arpack_defaults(), env = parent.frame(), complex = !sym ) @@ -223,5 +218,4 @@ Rich Lehoucq, Kristi Maschhoff, Danny Sorensen, Chao Yang for ARPACK, Gabor Csardi \email{csardi.gabor@gmail.com} for the R interface. } \concept{arpack} -\keyword{datasets} \keyword{graphs} diff --git a/man/centr_eigen.Rd b/man/centr_eigen.Rd index 68f00f972d1..2c2a7dfdc3a 100644 --- a/man/centr_eigen.Rd +++ b/man/centr_eigen.Rd @@ -9,7 +9,7 @@ centr_eigen( graph, directed = FALSE, scale = TRUE, - options = arpack_defaults, + options = arpack_defaults(), normalized = TRUE ) } diff --git a/man/cluster_leading_eigen.Rd b/man/cluster_leading_eigen.Rd index 9797582c908..a13c2b4f610 100644 --- a/man/cluster_leading_eigen.Rd +++ b/man/cluster_leading_eigen.Rd @@ -11,7 +11,7 @@ cluster_leading_eigen( steps = -1, weights = NULL, start = NULL, - options = arpack_defaults, + options = arpack_defaults(), callback = NULL, extra = NULL, env = parent.frame() diff --git a/man/eigen_centrality.Rd b/man/eigen_centrality.Rd index 176fc399c86..c6ce4b9d27a 100644 --- a/man/eigen_centrality.Rd +++ b/man/eigen_centrality.Rd @@ -10,7 +10,7 @@ eigen_centrality( directed = FALSE, scale = TRUE, weights = NULL, - options = arpack_defaults + options = arpack_defaults() ) } \arguments{ diff --git a/man/embed_adjacency_matrix.Rd b/man/embed_adjacency_matrix.Rd index 4c5eceb7e29..4657f50dfa2 100644 --- a/man/embed_adjacency_matrix.Rd +++ b/man/embed_adjacency_matrix.Rd @@ -11,7 +11,7 @@ embed_adjacency_matrix( which = c("lm", "la", "sa"), scaled = TRUE, cvec = graph.strength(graph, weights = weights)/(vcount(graph) - 1), - options = igraph.arpack.default + options = arpack_defaults() ) } \arguments{ @@ -42,7 +42,7 @@ graph. This vector is added to the diagonal of the adjacency matrix.} \item{options}{A named list containing the parameters for the SVD computation algorithm in ARPACK. By default, the list of values is assigned -the values given by \link{igraph.arpack.default}.} +the values given by \code{\link[=arpack_defaults]{arpack_defaults()}}.} } \value{ A list containing with entries: \item{X}{Estimated latent positions, diff --git a/man/embed_laplacian_matrix.Rd b/man/embed_laplacian_matrix.Rd index 15ff157d9d6..1cd32d10e43 100644 --- a/man/embed_laplacian_matrix.Rd +++ b/man/embed_laplacian_matrix.Rd @@ -11,7 +11,7 @@ embed_laplacian_matrix( which = c("lm", "la", "sa"), type = c("default", "D-A", "DAD", "I-DAD", "OAP"), scaled = TRUE, - options = igraph.arpack.default + options = arpack_defaults() ) } \arguments{ @@ -59,7 +59,7 @@ returned instead of \eqn{X} and \eqn{Y}.} \item{options}{A named list containing the parameters for the SVD computation algorithm in ARPACK. By default, the list of values is assigned -the values given by \link{igraph.arpack.default}.} +the values given by \code{\link[=arpack_defaults]{arpack_defaults()}}.} } \value{ A list containing with entries: \item{X}{Estimated latent positions, diff --git a/man/hub_score.Rd b/man/hub_score.Rd index 11a4bf7889b..a47357380e7 100644 --- a/man/hub_score.Rd +++ b/man/hub_score.Rd @@ -7,9 +7,14 @@ \alias{authority.score} \title{Kleinberg's hub and authority centrality scores.} \usage{ -hub_score(graph, scale = TRUE, weights = NULL, options = arpack_defaults) +hub_score(graph, scale = TRUE, weights = NULL, options = arpack_defaults()) -authority_score(graph, scale = TRUE, weights = NULL, options = arpack_defaults) +authority_score( + graph, + scale = TRUE, + weights = NULL, + options = arpack_defaults() +) } \arguments{ \item{graph}{The input graph.} diff --git a/man/layout_with_mds.Rd b/man/layout_with_mds.Rd index 2d00d42044d..d21994cdd8f 100644 --- a/man/layout_with_mds.Rd +++ b/man/layout_with_mds.Rd @@ -6,7 +6,7 @@ \alias{with_mds} \title{Graph layout by multidimensional scaling} \usage{ -layout_with_mds(graph, dist = NULL, dim = 2, options = arpack_defaults) +layout_with_mds(graph, dist = NULL, dim = 2, options = arpack_defaults()) with_mds(...) } diff --git a/man/spectrum.Rd b/man/spectrum.Rd index 9a6ee9e2c0d..cc3f1a4fee2 100644 --- a/man/spectrum.Rd +++ b/man/spectrum.Rd @@ -10,7 +10,7 @@ spectrum( graph, algorithm = c("arpack", "auto", "lapack", "comp_auto", "comp_lapack", "comp_arpack"), which = list(), - options = arpack_defaults + options = arpack_defaults() ) } \arguments{ diff --git a/tools/stimulus/types-RR.yaml b/tools/stimulus/types-RR.yaml index 13d8ecf4a9c..ef1bcf82ba4 100644 --- a/tools/stimulus/types-RR.yaml +++ b/tools/stimulus/types-RR.yaml @@ -286,11 +286,11 @@ EDGESETLIST: ARPACKOPT: INCONV: - INOUT: '%I%.tmp <- arpack_defaults; %I%.tmp[ names(%I%) ] <- %I% ; %I% <- %I%.tmp' + INOUT: '%I% <- modify_list(arpack_defaults(), %I%)' DRL_OPTIONS: INCONV: - IN: '%I%.tmp <- drl_defaults$default; %I%.tmp [names(%I%)] <- %I%; %I% <- %I%.tmp' + IN: '%I% <- modify_list(drl_defaults$default, %I%)' STRVECTOR: {} @@ -424,7 +424,7 @@ PAGERANKOPT: if (%I1% == 0L) { %I% <- list(niter=1000, eps=0.001) } else if (%I1% == 1L) { - %I% <- arpack_defaults + %I% <- arpack_defaults() } else { %I% <- NULL }