Skip to content

Commit 9f8a8a5

Browse files
committed
chore!: deprecation of scale param of eigen_centrality()
1 parent a54598a commit 9f8a8a5

5 files changed

Lines changed: 185 additions & 12 deletions

File tree

R/centrality.R

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -952,9 +952,8 @@ eigen_defaults <- function() {
952952
#' @param graph Graph to be analyzed.
953953
#' @param directed Logical scalar, whether to consider direction of the edges
954954
#' in directed graphs. It is ignored for undirected graphs.
955-
#' @param scale Logical scalar, whether to scale the result to have a maximum
956-
#' score of one. If no scaling is used then the result vector has unit length
957-
#' in the Euclidean norm.
955+
#' @param scale `lifecycle::badge("deprecated")` Normalization will always take
956+
#' place.
958957
#' @param weights A numerical vector or `NULL`. This argument can be used
959958
#' to give edge weights for calculating the weighted eigenvector centrality of
960959
#' vertices. If this is `NULL` and the graph has a `weight` edge
@@ -990,7 +989,7 @@ eigen_defaults <- function() {
990989
#' @cdocs igraph_eigenvector_centrality
991990
eigen_centrality <- function(graph,
992991
directed = FALSE,
993-
scale = TRUE,
992+
scale = deprecated(),
994993
weights = NULL,
995994
options = arpack_defaults()) {
996995

@@ -1003,9 +1002,24 @@ eigen_centrality <- function(graph,
10031002
options <- options()
10041003
}
10051004

1005+
if (lifecycle::is_present(scale)) {
1006+
if (scale) {
1007+
lifecycle::deprecate_soft(
1008+
"2.1.1",
1009+
"eigen_centrality(scale)",
1010+
details = "eigen_centrality() will always behave as if scale=TRUE were used."
1011+
)
1012+
} else {
1013+
lifecycle::deprecate_warn(
1014+
"2.1.1",
1015+
"eigen_centrality(scale = 'always as if TRUE')",
1016+
details = "Normalization is always performed")
1017+
}
1018+
}
1019+
10061020
eigenvector_centrality_impl(graph = graph,
10071021
directed = directed,
1008-
scale = scale,
1022+
scale = TRUE,
10091023
weights = weights,
10101024
options = options)
10111025
}

man/eigen_centrality.Rd

Lines changed: 3 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/evcent.Rd

Lines changed: 2 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/_snaps/centrality.md

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,159 @@
2424
i Please use `arpack_defaults()` instead.
2525
i So the function arpack_defaults(), not an object called arpack_defaults.
2626

27+
# eigen_centrality() deprecated scale argument
28+
29+
Code
30+
eigen_centrality(g, scale = TRUE)
31+
Condition
32+
Warning:
33+
The `scale` argument of `eigen_centrality()` is deprecated as of igraph 2.1.1.
34+
i eigen_centrality() will always behave as if scale=TRUE were used.
35+
Output
36+
$vector
37+
[1] 1 1 1 1 1 1 1 1 1 1
38+
39+
$value
40+
[1] 2
41+
42+
$options
43+
$options$bmat
44+
[1] "I"
45+
46+
$options$n
47+
[1] 10
48+
49+
$options$which
50+
[1] "LA"
51+
52+
$options$nev
53+
[1] 1
54+
55+
$options$tol
56+
[1] 0
57+
58+
$options$ncv
59+
[1] 0
60+
61+
$options$ldv
62+
[1] 0
63+
64+
$options$ishift
65+
[1] 1
66+
67+
$options$maxiter
68+
[1] 3000
69+
70+
$options$nb
71+
[1] 1
72+
73+
$options$mode
74+
[1] 1
75+
76+
$options$start
77+
[1] 1
78+
79+
$options$sigma
80+
[1] 0
81+
82+
$options$sigmai
83+
[1] 0
84+
85+
$options$info
86+
[1] 0
87+
88+
$options$iter
89+
[1] 1
90+
91+
$options$nconv
92+
[1] 1
93+
94+
$options$numop
95+
[1] 7
96+
97+
$options$numopb
98+
[1] 0
99+
100+
$options$numreo
101+
[1] 5
102+
103+
104+
105+
---
106+
107+
Code
108+
eigen_centrality(g, scale = FALSE)
109+
Condition
110+
Warning:
111+
The `scale` argument of `eigen_centrality()` always as if TRUE as of igraph 2.1.1.
112+
i Normalization is always performed
113+
Output
114+
$vector
115+
[1] 1 1 1 1 1 1 1 1 1 1
116+
117+
$value
118+
[1] 2
119+
120+
$options
121+
$options$bmat
122+
[1] "I"
123+
124+
$options$n
125+
[1] 10
126+
127+
$options$which
128+
[1] "LA"
129+
130+
$options$nev
131+
[1] 1
132+
133+
$options$tol
134+
[1] 0
135+
136+
$options$ncv
137+
[1] 0
138+
139+
$options$ldv
140+
[1] 0
141+
142+
$options$ishift
143+
[1] 1
144+
145+
$options$maxiter
146+
[1] 3000
147+
148+
$options$nb
149+
[1] 1
150+
151+
$options$mode
152+
[1] 1
153+
154+
$options$start
155+
[1] 1
156+
157+
$options$sigma
158+
[1] 0
159+
160+
$options$sigmai
161+
[1] 0
162+
163+
$options$info
164+
[1] 0
165+
166+
$options$iter
167+
[1] 1
168+
169+
$options$nconv
170+
[1] 1
171+
172+
$options$numop
173+
[1] 7
174+
175+
$options$numopb
176+
[1] 0
177+
178+
$options$numreo
179+
[1] 6
180+
181+
182+

tests/testthat/test-centrality.R

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,3 +690,8 @@ test_that("arpack works for non-symmetric matrices", {
690690

691691
# TODO: further tests for typically hard cases
692692

693+
test_that("eigen_centrality() deprecated scale argument", {
694+
g <- make_ring(10, directed = FALSE)
695+
expect_snapshot(eigen_centrality(g, scale = TRUE))
696+
expect_snapshot(eigen_centrality(g, scale = FALSE))
697+
})

0 commit comments

Comments
 (0)