Skip to content

Commit c995e5b

Browse files
committed
refactor: move optional arguments of trees functions behind the ellipsis
Insert `...` between the defining arguments and the optional modifiers of 4 functions, following the zoning rules in CONTRIBUTING.md. Legacy positional and abbreviated calls are recovered by the generated ARG_HANDLE blocks (registry: tools/migrations/trees.R) and emit a single soft deprecation for igraph 3.0.0. No defaults change and no arguments are renamed. Functions: is_chordal, is_forest, is_tree, sample_spanning_tree Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016M32izVHZPfxAqemAe4BrX
1 parent acbf688 commit c995e5b

8 files changed

Lines changed: 173 additions & 4 deletions

File tree

R/cycles.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#' a specific cycle.
3232
#'
3333
#' @param graph The input graph.
34+
#' @inheritParams rlang::args_dots_empty
3435
#' @param mode Character constant specifying how to handle directed graphs.
3536
#' `out` follows edge directions, `in` follows edges in the reverse direction,
3637
#' and `all` ignores edge directions. Ignored in undirected graphs.

R/decomposition.R

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ is.chordal <- function(
6767
#'
6868
#' @param graph The input graph. It may be directed, but edge directions are
6969
#' ignored, as the algorithm is defined for undirected graphs.
70+
#' @inheritParams rlang::args_dots_empty
7071
#' @param alpha Numeric vector, the maximal chardinality ordering of the
7172
#' vertices. If it is `NULL`, then it is automatically calculated by
7273
#' calling [max_cardinality()], or from `alpham1` if
@@ -118,11 +119,44 @@ is.chordal <- function(
118119
#'
119120
is_chordal <- function(
120121
graph,
122+
...,
121123
alpha = NULL,
122124
alpham1 = NULL,
123125
fillin = FALSE,
124126
newgraph = FALSE
125127
) {
128+
# BEGIN GENERATED ARG_HANDLE: is_chordal, do not edit, see tools/generate-migrations.R
129+
if (...length() > 0L) {
130+
.arg_handle <- migrate_recover_args(
131+
list(...),
132+
current = list(
133+
alpha = alpha,
134+
alpham1 = alpham1,
135+
fillin = fillin,
136+
newgraph = newgraph
137+
),
138+
recover_new = c("alpha", "alpham1", "fillin", "newgraph"),
139+
recover_old = c("alpha", "alpham1", "fillin", "newgraph"),
140+
match_names = c("alpha", "alpham1", "fillin", "newgraph"),
141+
match_to = c("alpha", "alpham1", "fillin", "newgraph"),
142+
defaults = list(
143+
alpha = NULL,
144+
alpham1 = NULL,
145+
fillin = FALSE,
146+
newgraph = FALSE
147+
),
148+
head_args = c("graph"),
149+
fn_name = "is_chordal"
150+
)
151+
list2env(.arg_handle$values, environment())
152+
lifecycle::deprecate_soft(
153+
"3.0.0",
154+
what = I(.arg_handle$what),
155+
details = .arg_handle$details
156+
)
157+
}
158+
# END GENERATED ARG_HANDLE
159+
126160
ensure_igraph(graph)
127161
if (!is.null(alpha)) {
128162
alpha <- as.numeric(alpha) - 1

R/trees.R

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#' not to be a tree.
1414
#'
1515
#' @param graph An igraph graph object
16+
#' @inheritParams rlang::args_dots_empty
1617
#' @param mode Whether to consider edge directions in a directed graph.
1718
#' \sQuote{all} ignores edge directions; \sQuote{out} requires edges to be
1819
#' oriented outwards from the root, \sQuote{in} requires edges to be oriented
@@ -42,9 +43,32 @@
4243
#' @export
4344
is_tree <- function(
4445
graph,
46+
...,
4547
mode = c("out", "in", "all", "total"),
4648
details = FALSE
4749
) {
50+
# BEGIN GENERATED ARG_HANDLE: is_tree, do not edit, see tools/generate-migrations.R
51+
if (...length() > 0L) {
52+
.arg_handle <- migrate_recover_args(
53+
list(...),
54+
current = list(mode = mode, details = details),
55+
recover_new = c("mode", "details"),
56+
recover_old = c("mode", "details"),
57+
match_names = c("mode", "details"),
58+
match_to = c("mode", "details"),
59+
defaults = list(mode = c("out", "in", "all", "total"), details = FALSE),
60+
head_args = c("graph"),
61+
fn_name = "is_tree"
62+
)
63+
list2env(.arg_handle$values, environment())
64+
lifecycle::deprecate_soft(
65+
"3.0.0",
66+
what = I(.arg_handle$what),
67+
details = .arg_handle$details
68+
)
69+
}
70+
# END GENERATED ARG_HANDLE
71+
4872
out <- is_tree_impl(
4973
graph = graph,
5074
mode = mode,
@@ -72,6 +96,7 @@ is_tree <- function(
7296
#' to be a forest.
7397
#'
7498
#' @param graph An igraph graph object
99+
#' @inheritParams rlang::args_dots_empty
75100
#' @param mode Whether to consider edge directions in a directed graph.
76101
#' \sQuote{all} ignores edge directions; \sQuote{out} requires edges to be
77102
#' oriented outwards from the root, \sQuote{in} requires edges to be oriented
@@ -101,9 +126,32 @@ is_tree <- function(
101126
#' @export
102127
is_forest <- function(
103128
graph,
129+
...,
104130
mode = c("out", "in", "all", "total"),
105131
details = FALSE
106132
) {
133+
# BEGIN GENERATED ARG_HANDLE: is_forest, do not edit, see tools/generate-migrations.R
134+
if (...length() > 0L) {
135+
.arg_handle <- migrate_recover_args(
136+
list(...),
137+
current = list(mode = mode, details = details),
138+
recover_new = c("mode", "details"),
139+
recover_old = c("mode", "details"),
140+
match_names = c("mode", "details"),
141+
match_to = c("mode", "details"),
142+
defaults = list(mode = c("out", "in", "all", "total"), details = FALSE),
143+
head_args = c("graph"),
144+
fn_name = "is_forest"
145+
)
146+
list2env(.arg_handle$values, environment())
147+
lifecycle::deprecate_soft(
148+
"3.0.0",
149+
what = I(.arg_handle$what),
150+
details = .arg_handle$details
151+
)
152+
}
153+
# END GENERATED ARG_HANDLE
154+
107155
is_forest_impl(
108156
graph = graph,
109157
mode = mode,
@@ -148,6 +196,7 @@ to_prufer <- function(graph) {
148196
#'
149197
#' @param graph The input graph to sample from. Edge directions are ignored if
150198
#' the graph is directed.
199+
#' @inheritParams rlang::args_dots_empty
151200
#' @param vid When the graph is disconnected, this argument specifies how to
152201
#' handle the situation. When the argument is zero (the default), the sampling
153202
#' will be performed component-wise, and the result will be a spanning forest.
@@ -167,7 +216,33 @@ to_prufer <- function(graph) {
167216
#'
168217
#' @family trees
169218
#' @export
170-
sample_spanning_tree <- function(graph, vid = 0) {
219+
sample_spanning_tree <- function(
220+
graph,
221+
...,
222+
vid = 0
223+
) {
224+
# BEGIN GENERATED ARG_HANDLE: sample_spanning_tree, do not edit, see tools/generate-migrations.R
225+
if (...length() > 0L) {
226+
.arg_handle <- migrate_recover_args(
227+
list(...),
228+
current = list(vid = vid),
229+
recover_new = c("vid"),
230+
recover_old = c("vid"),
231+
match_names = c("vid"),
232+
match_to = c("vid"),
233+
defaults = list(vid = 0),
234+
head_args = c("graph"),
235+
fn_name = "sample_spanning_tree"
236+
)
237+
list2env(.arg_handle$values, environment())
238+
lifecycle::deprecate_soft(
239+
"3.0.0",
240+
what = I(.arg_handle$what),
241+
details = .arg_handle$details
242+
)
243+
}
244+
# END GENERATED ARG_HANDLE
245+
171246
random_spanning_tree_impl(
172247
graph = graph,
173248
vid = vid

man/is_chordal.Rd

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

man/is_forest.Rd

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

man/is_tree.Rd

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

man/sample_spanning_tree.Rd

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

tools/migrations/trees.R

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Argument-signature migrations: trees
2+
# Schema: see tools/migrations.R. Regenerate with:
3+
# Rscript tools/generate-migrations.R
4+
5+
migrations <- list(
6+
is_chordal = list(
7+
old = function(graph, alpha, alpham1, fillin, newgraph) {},
8+
new = function(
9+
graph,
10+
...,
11+
alpha = NULL,
12+
alpham1 = NULL,
13+
fillin = FALSE,
14+
newgraph = FALSE
15+
) {},
16+
when = "3.0.0"
17+
),
18+
19+
is_forest = list(
20+
old = function(graph, mode, details) {},
21+
new = function(
22+
graph,
23+
...,
24+
mode = c("out", "in", "all", "total"),
25+
details = FALSE
26+
) {},
27+
when = "3.0.0"
28+
),
29+
30+
is_tree = list(
31+
old = function(graph, mode, details) {},
32+
new = function(
33+
graph,
34+
...,
35+
mode = c("out", "in", "all", "total"),
36+
details = FALSE
37+
) {},
38+
when = "3.0.0"
39+
),
40+
41+
sample_spanning_tree = list(
42+
old = function(graph, vid) {},
43+
new = function(
44+
graph,
45+
...,
46+
vid = 0
47+
) {},
48+
when = "3.0.0"
49+
)
50+
)

0 commit comments

Comments
 (0)