Skip to content
Open
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
49 changes: 35 additions & 14 deletions R/centrality.R
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,8 @@ edge.betweenness <- function(
#' `bonpow()` was renamed to [power_centrality()] to create a more
#' consistent API.
#' @inheritParams power_centrality
#' @param rescale `r lifecycle::badge("deprecated")` Use `normalized` in
#' [power_centrality()] instead.
#' @keywords internal
#' @export
bonpow <- function(
Expand All @@ -251,7 +253,7 @@ bonpow <- function(
nodes = nodes,
loops = loops,
exponent = exponent,
rescale = rescale,
normalized = rescale,
tol = tol,
sparse = sparse
)
Expand Down Expand Up @@ -1719,7 +1721,7 @@ diversity <- function(
#' scores are the same as authority scores.
#'
#' @param graph The input graph.
#' @param scale Logical, whether to scale the result to have a maximum
#' @param normalized Logical, whether to scale the result to have a maximum
#' score of one. If no scaling is used then the result vector has unit length
#' in the Euclidean norm.
#' @param weights Optional positive weight vector for calculating weighted
Expand All @@ -1729,6 +1731,7 @@ diversity <- function(
#' edges are effectively added up.
#' @param options A named list, to override some ARPACK options. See
#' [arpack()] for details. The default `NULL` uses [arpack_defaults()].
#' @param scale `r lifecycle::badge("deprecated")` Use `normalized` instead.
#' @inheritParams rlang::args_dots_empty
#' @return A named list with members:
#' \describe{
Expand Down Expand Up @@ -1766,19 +1769,35 @@ diversity <- function(
hits_scores <- function(
graph,
...,
scale = TRUE,
normalized = TRUE,
weights = NULL,
options = NULL
options = NULL,
scale = deprecated()
) {
rlang::check_dots_empty()

if (lifecycle::is_present(scale)) {
if (!missing(normalized)) {
cli::cli_abort(c(
"Argument {.arg normalized} of {.fn hits_scores} was supplied more than once.",
i = "It was also supplied via its legacy name {.arg scale}."
))
}
lifecycle::deprecate_soft(
"3.0.0",
"hits_scores(scale = )",
"hits_scores(normalized = )"
)
normalized <- scale
}

if (is.null(options)) {
options <- arpack_defaults()
}

hub_and_authority_scores_impl(
graph = graph,
scale = scale,
scale = normalized,
weights = weights,
options = options
)
Expand Down Expand Up @@ -1810,7 +1829,7 @@ authority_score <- function(

scores <- hits_scores(
graph = graph,
scale = scale,
normalized = scale,
weights = weights,
options = options
)
Expand Down Expand Up @@ -1855,7 +1874,7 @@ hub_score <- function(

scores <- hits_scores(
graph = graph,
scale = scale,
normalized = scale,
weights = weights,
options = options
)
Expand Down Expand Up @@ -2266,7 +2285,7 @@ bonpow.sparse <- function(
#' loops. `loops` is `FALSE` by default.
#' @param exponent exponent (decay rate) for the Bonacich power centrality
#' score; can be negative
#' @param rescale if true, centrality scores are rescaled such that they sum to
#' @param normalized if true, centrality scores are rescaled such that they sum to
#' 1.
#' @param tol tolerance for near-singularities during matrix inversion (see
#' [solve()])
Expand Down Expand Up @@ -2325,14 +2344,16 @@ power_centrality <- function(
...,
loops = FALSE,
exponent = 1,
rescale = FALSE,
normalized = FALSE,
tol = 1e-7,
sparse = TRUE,
weights = NULL
) {
# BEGIN GENERATED ARG_HANDLE: power_centrality, do not edit, see tools/generate-migrations.R
# fmt: skip
if (...length() > 0L) {
.arg_forbidden <- base::intersect(base::names(base::sys.call()), base::c("n", "no"))
if (base::length(.arg_forbidden) > 0L) cli::cli_abort(base::c("Argument {.arg {(.arg_forbidden)}} matches multiple formal arguments of {.fn power_centrality}.", i = "Spell out the full argument name."))
# Pre-3.0.0 signature: power_centrality(graph, nodes, loops, exponent, rescale, tol, sparse, weights)
.old_signature <- function(loops, exponent, rescale, tol, sparse, weights, ...) {
if (...length() > 0L) {
Expand All @@ -2344,7 +2365,7 @@ power_centrality <- function(
base::c(
if (!base::missing(loops)) base::list(loops = loops),
if (!base::missing(exponent)) base::list(exponent = exponent),
if (!base::missing(rescale)) base::list(rescale = rescale),
if (!base::missing(rescale)) base::list(normalized = rescale),
if (!base::missing(tol)) base::list(tol = tol),
if (!base::missing(sparse)) base::list(sparse = sparse),
if (!base::missing(weights)) base::list(weights = weights)
Expand All @@ -2356,7 +2377,7 @@ power_centrality <- function(
.arg_conflict <- base::intersect(.arg_names, base::c(
if (!base::missing(loops)) "loops",
if (!base::missing(exponent)) "exponent",
if (!base::missing(rescale)) "rescale",
if (!base::missing(normalized)) "normalized",
if (!base::missing(tol)) "tol",
if (!base::missing(sparse)) "sparse",
if (!base::missing(weights)) "weights"
Expand All @@ -2367,7 +2388,7 @@ power_centrality <- function(
"3.0.0",
what = base::I("Calling `power_centrality()` with positional or abbreviated arguments"),
details = base::c(
i = base::paste0("Detected call: power_centrality(", base::paste(base::c("graph", "nodes", .arg_names), collapse = ", "), ")"),
i = base::paste0("Detected call: power_centrality(", base::paste(base::c("graph", "nodes", base::c(loops = "loops", exponent = "exponent", normalized = "rescale", tol = "tol", sparse = "sparse", weights = "weights")[.arg_names]), collapse = ", "), ")"),
i = base::paste0("Use instead: power_centrality(", base::paste(base::c("graph", "nodes", base::paste0(.arg_names, " = ")), collapse = ", "), ")")
)
)
Expand All @@ -2386,7 +2407,7 @@ power_centrality <- function(
nodes,
loops,
exponent,
rescale,
normalized,
tol,
weights = weights
)
Expand All @@ -2396,7 +2417,7 @@ power_centrality <- function(
nodes,
loops,
exponent,
rescale,
normalized,
tol,
weights = weights
)
Expand Down
20 changes: 12 additions & 8 deletions R/tkplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,14 @@ tkplot.off <- function() {
#' `tkplot.getcoords()` was renamed to [tk_coords()] to create a more
#' consistent API.
#' @inheritParams tk_coords
#' @param norm `r lifecycle::badge("deprecated")` Use `normalized` in
#' [tk_coords()] instead.
#' @keywords internal
#' @export
tkplot.getcoords <- function(tkp.id, norm = FALSE) {
# nocov start
lifecycle::deprecate_warn("2.0.0", "tkplot.getcoords()", "tk_coords()")
tk_coords(tkp.id = tkp.id, norm = norm)
tk_coords(tkp.id = tkp.id, normalized = norm)
} # nocov end

#' Interactive plotting of graphs
Expand Down Expand Up @@ -271,7 +273,7 @@ assign(".next", 1, .tkplot.env)
#' @param width The width of the rectangle for generating new coordinates.
#' @param height The height of the rectangle for generating new coordinates.
#' @param newlayout The new layout, see the `layout` parameter of tkplot.
#' @param norm Logical, should we norm the coordinates.
#' @param normalized Logical, should we norm the coordinates.
#' @param coords Two-column numeric matrix, the new coordinates of the
#' vertices, in absolute coordinates.
#' @param degree The degree to rotate the plot.
Expand Down Expand Up @@ -734,11 +736,13 @@ tk_postscript <- function(tkp.id) {
tk_coords <- function(
tkp.id,
...,
norm = FALSE
normalized = FALSE
) {
# BEGIN GENERATED ARG_HANDLE: tk_coords, do not edit, see tools/generate-migrations.R
# fmt: skip
if (...length() > 0L) {
.arg_ambiguous <- base::intersect(base::names(base::substitute(...())), base::c("n", "no", "nor"))
if (base::length(.arg_ambiguous) > 0L) cli::cli_abort("Argument {.arg {(.arg_ambiguous[[1L]])}} matches multiple arguments of {.fn tk_coords}.")
# Pre-3.0.0 signature: tk_coords(tkp.id, norm)
.old_signature <- function(norm, ...) {
if (...length() > 0L) {
Expand All @@ -748,22 +752,22 @@ tk_coords <- function(
cli::cli_abort(base::c("Unexpected argument passed to {.fn tk_coords}: {.arg {(.arg_extra)}}.", i = "Arguments after {.arg ...} must be spelled out in full."), call = base::parent.frame())
}
base::c(
if (!base::missing(norm)) base::list(norm = norm)
if (!base::missing(norm)) base::list(normalized = norm)
)
}
.arg_handle <- .old_signature(...)
if (base::length(.arg_handle) > 0L) {
.arg_names <- base::names(.arg_handle)
.arg_conflict <- base::intersect(.arg_names, base::c(
if (!base::missing(norm)) "norm"
if (!base::missing(normalized)) "normalized"
))
if (base::length(.arg_conflict) > 0L) cli::cli_abort(base::c("Argument {.arg {(.arg_conflict)}} of {.fn tk_coords} was supplied more than once.", i = "Pass it exactly once, by its new name {.arg {(.arg_conflict)}}."))
base::list2env(.arg_handle, base::environment())
lifecycle::deprecate_soft(
"3.0.0",
what = base::I("Calling `tk_coords()` with positional or abbreviated arguments"),
details = base::c(
i = base::paste0("Detected call: tk_coords(", base::paste(base::c("tkp.id", .arg_names), collapse = ", "), ")"),
i = base::paste0("Detected call: tk_coords(", base::paste(base::c("tkp.id", base::c(normalized = "norm")[.arg_names]), collapse = ", "), ")"),
i = base::paste0("Use instead: tk_coords(", base::paste(base::c("tkp.id", base::paste0(.arg_names, " = ")), collapse = ", "), ")")
)
)
Expand All @@ -774,7 +778,7 @@ tk_coords <- function(
# nocov start
coords <- .tkplot.get(tkp.id, "coords")
coords[, 2] <- max(coords[, 2]) - coords[, 2]
if (norm) {
if (normalized) {
# Shift
coords[, 1] <- coords[, 1] - min(coords[, 1])
coords[, 2] <- coords[, 2] - min(coords[, 2])
Expand Down Expand Up @@ -1845,7 +1849,7 @@ tk_canvas <- function(tkp.id) {
layout$params[[i]]$type == "initial" &&
params[[i]]
) {
realparams[[i]] <- tk_coords(tkp.id, norm = TRUE)
realparams[[i]] <- tk_coords(tkp.id, normalized = TRUE)
}
}
if (as.logical(tcltk::tclvalue(save.default))) {
Expand Down
4 changes: 2 additions & 2 deletions man/bonpow.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 11 additions & 2 deletions man/hits_scores.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/power_centrality.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/tkplot.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion man/tkplot.getcoords.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions tests/testthat/_snaps/centrality.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,24 @@
i Please use `arpack_defaults()` instead.
i So the function arpack_defaults(), not an object called arpack_defaults.

# hits_scores(scale = ) is deprecated but still works

Code
res_legacy <- hits_scores(g, scale = FALSE)
Condition
Warning:
The `scale` argument of `hits_scores()` is deprecated as of igraph 3.0.0.
i Please use the `normalized` argument instead.

---

Code
hits_scores(g, normalized = FALSE, scale = FALSE)
Condition
Error in `hits_scores()`:
! Argument `normalized` of `hits_scores()` was supplied more than once.
i It was also supplied via its legacy name `scale`.

# eigen_centrality() deprecated scale argument

Code
Expand Down
Loading
Loading