Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,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)
Expand Down
30 changes: 15 additions & 15 deletions R/aaa-auto.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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 <- modify_list(arpack_defaults(), options)

on.exit( .Call(R_igraph_finalizer) )
# Function call
Expand All @@ -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)
Expand All @@ -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 <- modify_list(arpack_defaults(), options)

on.exit( .Call(R_igraph_finalizer) )
# Function call
Expand Down Expand Up @@ -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 <- modify_list(arpack_defaults(), options)
normalized <- as.logical(normalized)

on.exit( .Call(R_igraph_finalizer) )
Expand Down Expand Up @@ -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)
Expand All @@ -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 <- modify_list(arpack_defaults(), options)

on.exit( .Call(R_igraph_finalizer) )
# Function call
Expand All @@ -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)
Expand All @@ -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 <- modify_list(arpack_defaults(), options)

on.exit( .Call(R_igraph_finalizer) )
# Function call
Expand All @@ -2064,15 +2064,15 @@ 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,
"arpack"=2, "comp_auto"=3, "comp_lapack"=4,
"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 <- modify_list(arpack_defaults(), options)

on.exit( .Call(R_igraph_finalizer) )
# Function call
Expand Down
117 changes: 101 additions & 16 deletions R/centrality.R
Original file line number Diff line number Diff line change
Expand Up @@ -318,11 +318,13 @@ closeness.estimate <- estimate_closeness
#' @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
#'
Expand Down Expand Up @@ -431,7 +433,7 @@ arpack_defaults <- list(
#' re-orthogonalization.} } } Please see the ARPACK documentation for
#' additional details.
#'
#' @aliases arpack arpack-options igraph.arpack.default arpack.unpack.complex
#' @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}
Expand Down Expand Up @@ -512,27 +514,38 @@ 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)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why eval_tidy()? We should be able to do this with standard evaluation, forcing should be enough?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you have any example I could look at?

if (is.function(options)) {
lifecycle::deprecate_soft(
"2.0.0",
"arpack_defaults(options = 'must be a list')",
details = c("`arpack_defaults()` is now a function, use `options = arpack_defaults()` instead of `options = arpack_defaults`.")
)
options <- options()
}

if (!is.list(options) ||
(is.null(names(options)) && length(options) != 0)) {
stop("options must be a named list")
}
if (any(names(options) == "")) {
stop("all options must be named")
}
if (any(!names(options) %in% names(arpack_defaults))) {

defaults <- arpack_defaults()
if (any(!names(options) %in% names(defaults))) {
stop(
"unkown ARPACK option(s): ",
paste(setdiff(names(options), names(arpack_defaults)),
paste(setdiff(names(options), names(defaults)),
collapse = ", "
)
)
}

options.tmp <- arpack_defaults
options.tmp[names(options)] <- options
options <- options.tmp
options <- modify_list(defaults, options)

if (sym && complex) {
complex <- FALSE
Expand Down Expand Up @@ -692,7 +705,24 @@ subgraph_centrality <- function(graph, diag = FALSE) {
#'
#' @family centrality
#' @export
spectrum <- eigen_adjacency_impl
spectrum <- function(graph, algorithm=c("arpack", "auto", "lapack", "comp_auto", "comp_lapack", "comp_arpack"), which=list(), options=arpack_defaults()) {
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 arpack_defaults.")
)
options <- arpack_defaults()
}

eigen_adjacency_impl(graph,
algorithm = algorithm,
which = which,
options = options)
}

eigen_defaults <- function() {
list(
Expand Down Expand Up @@ -787,8 +817,30 @@ eigen_defaults <- function() {
#' eigen_centrality(g)
#' @family centrality
#' @export
eigen_centrality <- eigenvector_centrality_impl
eigen_centrality <- function(graph,
directed = FALSE,
scale = TRUE,
weights = NULL,
options = arpack_defaults()) {

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 arpack_defaults.")
)
options <- arpack_defaults()
}

eigenvector_centrality_impl(graph = graph,
directed = directed,
scale = scale,
weights = weights,
options = options)
}

#' Strength or weighted vertex degree
#'
Expand Down Expand Up @@ -927,16 +979,49 @@ diversity <- diversity_impl
#' hub_score(g2)$vector
#' authority_score(g2)$vector
#' @family centrality
hub_score <- hub_score_impl
hub_score <- function(graph, scale=TRUE, weights=NULL, options=arpack_defaults()) {

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 arpack_defaults.")
)
options <- arpack_defaults()
}

hub_score_impl(graph = graph,
scale = scale,
weights = weights,
options = options)
}

#' @rdname hub_score
#' @aliases authority.score
#' @param options A named list, to override some ARPACK options. See
#' [arpack()] for details.
#' @export
authority_score <- authority_score_impl
authority_score <- function(graph, scale=TRUE, weights=NULL, options=arpack_defaults()) {
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 arpack_defaults.")
)
options <- arpack_defaults()
}

authority_score_impl(graph = graph,
scale = scale,
weights = weights,
options = options)
}

#' The Page Rank algorithm
#'
Expand Down
20 changes: 16 additions & 4 deletions R/community.R
Original file line number Diff line number Diff line change
Expand Up @@ -1621,9 +1621,22 @@ 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()) {

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 arpack_defaults.")
)
options <- arpack_defaults()
}

# Argument checks
ensure_igraph(graph)

Expand All @@ -1639,9 +1652,8 @@ 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
Expand Down
4 changes: 2 additions & 2 deletions R/embedding.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
15 changes: 14 additions & 1 deletion R/layout.R
Original file line number Diff line number Diff line change
Expand Up @@ -1517,7 +1517,20 @@ 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()) {

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 arpack_defaults.")
)
options <- arpack_defaults()
}

# Argument checks
ensure_igraph(graph)
if (!is.null(dist)) dist <- structure(as.double(dist), dim = dim(dist))
Expand Down
Loading