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
24 changes: 24 additions & 0 deletions R/coloring.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#' linear time.
#'
#' @param graph The graph object to color.
#' @inheritParams rlang::args_dots_empty
#' @param heuristic The selection heuristic for the next vertex to consider.
#' Possible values are: \dQuote{colored_neighbors} selects the vertex with the
#' largest number of already colored neighbors. \dQuote{dsatur} selects the
Expand All @@ -32,8 +33,31 @@
#'
greedy_vertex_coloring <- function(
graph,
...,
heuristic = c("colored_neighbors", "dsatur")
) {
# BEGIN GENERATED ARG_HANDLE: greedy_vertex_coloring, do not edit, see tools/generate-migrations.R
if (...length() > 0L) {
.arg_handle <- migrate_recover_args(
list(...),
current = list(heuristic = heuristic),
recover_new = c("heuristic"),
recover_old = c("heuristic"),
match_names = c("heuristic"),
match_to = c("heuristic"),
defaults = list(heuristic = c("colored_neighbors", "dsatur")),
head_args = c("graph"),
fn_name = "greedy_vertex_coloring"
)
list2env(.arg_handle$values, environment())
lifecycle::deprecate_soft(
"3.0.0",
what = I(.arg_handle$what),
details = .arg_handle$details
)
}
# END GENERATED ARG_HANDLE

vertex_coloring_greedy_impl(
graph = graph,
heuristic = heuristic
Expand Down
1 change: 1 addition & 0 deletions R/cycles.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#' a specific cycle.
#'
#' @param graph The input graph.
#' @inheritParams rlang::args_dots_empty
#' @param mode Character constant specifying how to handle directed graphs.
#' `out` follows edge directions, `in` follows edges in the reverse direction,
#' and `all` ignores edge directions. Ignored in undirected graphs.
Expand Down
31 changes: 29 additions & 2 deletions R/epi.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,43 @@
###################################################################

#' @rdname sir
#' @inheritParams rlang::args_dots_empty
#' @export
time_bins <- function(x, middle = TRUE) {
time_bins <- function(
x,
...,
middle = TRUE
) {
UseMethod("time_bins")
}

#' @method time_bins sir
#' @rdname sir
#' @export
#' @importFrom stats IQR
time_bins.sir <- function(x, middle = TRUE) {
time_bins.sir <- function(x, ..., middle = TRUE) {
# BEGIN GENERATED ARG_HANDLE: time_bins, do not edit, see tools/generate-migrations.R
if (...length() > 0L) {
.arg_handle <- migrate_recover_args(
list(...),
current = list(middle = middle),
recover_new = c("middle"),
recover_old = c("middle"),
match_names = c("middle"),
match_to = c("middle"),
defaults = list(middle = TRUE),
head_args = c("x"),
fn_name = "time_bins"
)
list2env(.arg_handle$values, environment())
lifecycle::deprecate_soft(
"3.0.0",
what = I(.arg_handle$what),
details = .arg_handle$details
)
}
# END GENERATED ARG_HANDLE

sir <- x

big.time <- unlist(sapply(sir, "[[", "times"))
Expand Down
78 changes: 78 additions & 0 deletions R/foreign.R
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,7 @@ write.graph.dot <- function(graph, file) {
#' for the actual format of a graph database file and other information.
#'
#' @param url Complete URL with the file to import. Default: `NULL`.
#' @inheritParams rlang::args_dots_empty
#' @param prefix Gives the prefix. See details below. Possible values:
#' `iso`, `i2`, `si4`, `si6`, `mcs10`, `mcs30`,
#' `mcs50`, `mcs70`, `mcs90`.
Expand Down Expand Up @@ -825,6 +826,7 @@ write.graph.dot <- function(graph, file) {
#' @keywords graphs
graph_from_graphdb <- function(
url = NULL,
...,
prefix = "iso",
type = "r001",
nodes = NULL,
Expand All @@ -834,6 +836,82 @@ graph_from_graphdb <- function(
compressed = TRUE,
directed = TRUE
) {
# BEGIN GENERATED ARG_HANDLE: graph_from_graphdb, do not edit, see tools/generate-migrations.R
if (...length() > 0L) {
.arg_handle <- migrate_recover_args(
list(...),
current = list(
prefix = prefix,
type = type,
nodes = nodes,
pair = pair,
which = which,
base = base,
compressed = compressed,
directed = directed
),
recover_new = c(
"prefix",
"type",
"nodes",
"pair",
"which",
"base",
"compressed",
"directed"
),
recover_old = c(
"prefix",
"type",
"nodes",
"pair",
"which",
"base",
"compressed",
"directed"
),
match_names = c(
"prefix",
"type",
"nodes",
"pair",
"which",
"base",
"compressed",
"directed"
),
match_to = c(
"prefix",
"type",
"nodes",
"pair",
"which",
"base",
"compressed",
"directed"
),
defaults = list(
prefix = "iso",
type = "r001",
nodes = NULL,
pair = "A",
which = 0,
base = "https://github.com/igraph/graphsdb/raw/refs/heads/main",
compressed = TRUE,
directed = TRUE
),
head_args = c("url"),
fn_name = "graph_from_graphdb"
)
list2env(.arg_handle$values, environment())
lifecycle::deprecate_soft(
"3.0.0",
what = I(.arg_handle$what),
details = .arg_handle$details
)
}
# END GENERATED ARG_HANDLE

if (is.null(nodes) && is.null(url)) {
cli::cli_abort("Either {.arg nodes}' or `{.arg url}' must be non-null.")
}
Expand Down
31 changes: 30 additions & 1 deletion R/sir.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
#' @param gamma Positive scalar. The rate of recovery of an infected
#' individual. Formally, this is the rate parameter of an exponential
#' distribution.
#' @inheritParams rlang::args_dots_empty
#' @param no.sim Integer scalar, the number simulation runs to perform.
#' @param x A `sir` object, returned by the `sir()` function.
#' @param middle Logical, whether to return the middle of the time bins,
Expand Down Expand Up @@ -108,7 +109,35 @@
#' plot(sm)
#' @family processes
#' @export
sir <- function(graph, beta, gamma, no.sim = 100) {
sir <- function(
graph,
beta,
gamma,
...,
no.sim = 100
) {
# BEGIN GENERATED ARG_HANDLE: sir, do not edit, see tools/generate-migrations.R
if (...length() > 0L) {
.arg_handle <- migrate_recover_args(
list(...),
current = list(no.sim = no.sim),
recover_new = c("no.sim"),
recover_old = c("no.sim"),
match_names = c("no.sim"),
match_to = c("no.sim"),
defaults = list(no.sim = 100),
head_args = c("graph", "beta", "gamma"),
fn_name = "sir"
)
list2env(.arg_handle$values, environment())
lifecycle::deprecate_soft(
"3.0.0",
what = I(.arg_handle$what),
details = .arg_handle$details
)
}
# END GENERATED ARG_HANDLE

sir_impl(
graph = graph,
beta = beta,
Expand Down
27 changes: 27 additions & 0 deletions R/stochastic_matrix.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ get.stochastic <- function(
#' matrices are defined in a symmetric way.
#'
#' @param graph The input graph. Must be of class `igraph`.
#' @inheritParams rlang::args_dots_empty
#' @param column.wise If `FALSE`, then the rows of the stochastic matrix
#' sum up to one; otherwise it is the columns.
#' @param sparse Logical, whether to return a sparse matrix. The
Expand All @@ -76,9 +77,35 @@ get.stochastic <- function(
#'
stochastic_matrix <- function(
graph,
...,
column.wise = FALSE,
sparse = igraph_opt("sparsematrices")
) {
# BEGIN GENERATED ARG_HANDLE: stochastic_matrix, do not edit, see tools/generate-migrations.R
if (...length() > 0L) {
.arg_handle <- migrate_recover_args(
list(...),
current = list(column.wise = column.wise, sparse = sparse),
recover_new = c("column.wise", "sparse"),
recover_old = c("column.wise", "sparse"),
match_names = c("column.wise", "sparse"),
match_to = c("column.wise", "sparse"),
defaults = list(
column.wise = FALSE,
sparse = igraph_opt("sparsematrices")
),
head_args = c("graph"),
fn_name = "stochastic_matrix"
)
list2env(.arg_handle$values, environment())
lifecycle::deprecate_soft(
"3.0.0",
what = I(.arg_handle$what),
details = .arg_handle$details
)
}
# END GENERATED ARG_HANDLE

ensure_igraph(graph)

column.wise <- as.logical(column.wise)
Expand Down
3 changes: 3 additions & 0 deletions man/graph_from_graphdb.Rd

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

8 changes: 7 additions & 1 deletion man/greedy_vertex_coloring.Rd

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

10 changes: 5 additions & 5 deletions man/sir.Rd

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

3 changes: 3 additions & 0 deletions man/stochastic_matrix.Rd

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

12 changes: 12 additions & 0 deletions tests/testthat/test-coloring.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,15 @@ test_that("simplify_and_colorize works", {
expect_equal(V(result)$color, c(0, 0, 0, 0, 1))
expect_equal(E(result)$color, c(1, 4, 1, 2))
})

# ---- ellipsis migration: argument coverage ----------------------------------
# The `heuristic` tail argument is already exercised by name in the tests above,
# so here we only cover the legacy positional recovery path.

test_that("greedy_vertex_coloring() recovers a legacy positional `heuristic`", {
g <- make_star(10, mode = "undirected")
lifecycle::expect_deprecated(
col <- greedy_vertex_coloring(g, "dsatur")
)
expect_identical(col, greedy_vertex_coloring(g, heuristic = "dsatur"))
})
Loading
Loading