From 3658b2662b3ac7bfb8adbe16f2705dfbccf04e2e Mon Sep 17 00:00:00 2001 From: olivroy <52606734+olivroy@users.noreply.github.com> Date: Thu, 22 Aug 2024 17:44:53 -0400 Subject: [PATCH] Drop ellipsis for rlang + use `check_installed()` to install packages on the fly (#37) * Drop ellipsis for rlang * Use `rlang::check_installed()` to install missing packages on the fly. --- DESCRIPTION | 2 +- R/directed_factor_model.R | 2 +- R/expected-degrees.R | 2 +- R/expected-spectra.R | 21 +++------------------ R/sample_edgelist.R | 2 +- R/sample_igraph.R | 10 ++-------- R/sample_sparse.R | 2 +- R/sample_tidygraph.R | 11 ++--------- R/undirected_factor_model.R | 2 +- 9 files changed, 13 insertions(+), 41 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 2863822..793ab66 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -26,11 +26,11 @@ Depends: Matrix Imports: dplyr, - ellipsis, ggplot2, glue, igraph, methods, + rlang (>= 1.0.0), RSpectra, stats, tibble, diff --git a/R/directed_factor_model.R b/R/directed_factor_model.R index d8af5cf..ed19e2c 100644 --- a/R/directed_factor_model.R +++ b/R/directed_factor_model.R @@ -4,7 +4,7 @@ new_directed_factor_model <- function( allow_self_loops, ..., subclass = character()) { - ellipsis::check_dots_unnamed() + rlang::check_dots_unnamed() n <- nrow(X) k1 <- ncol(X) diff --git a/R/expected-degrees.R b/R/expected-degrees.R index 98c8309..edf8186 100644 --- a/R/expected-degrees.R +++ b/R/expected-degrees.R @@ -69,7 +69,7 @@ #' svds(dfm) #' expected_edges <- function(factor_model, ...) { - ellipsis::check_dots_empty() + rlang::check_dots_empty() UseMethod("expected_edges") } diff --git a/R/expected-spectra.R b/R/expected-spectra.R index 456aeeb..9863904 100644 --- a/R/expected-spectra.R +++ b/R/expected-spectra.R @@ -20,12 +20,7 @@ eigs_sym.undirected_factor_model <- function( which = "LM", sigma = NULL, opts = list(), ...) { - if (!requireNamespace("RSpectra", quietly = TRUE)) { - stop( - "Must install `RSpectra` for this functionality.", - call. = FALSE - ) - } + rlang::check_installed("RSpectra") Ax <- function(x, args) as.numeric(args$X %*% (args$SXt %*% x)) @@ -48,12 +43,7 @@ svds.undirected_factor_model <- function( nv = k, opts = list(), ...) { - if (!requireNamespace("RSpectra", quietly = TRUE)) { - stop( - "Must install `RSpectra` for this functionality.", - call. = FALSE - ) - } + rlang::check_installed("RSpectra") Ax <- function(x, args) { as.numeric(args$X %*% (tcrossprod(args$S, args$X) %*% x)) @@ -92,12 +82,7 @@ svds.directed_factor_model <- function( nv = k, opts = list(), ...) { - if (!requireNamespace("RSpectra", quietly = TRUE)) { - stop( - "Must install `RSpectra` for this functionality.", - call. = FALSE - ) - } + rlang::check_installed("RSpectra") Ax <- function(x, args) { as.numeric(args$X %*% (tcrossprod(args$S, args$Y) %*% x)) diff --git a/R/sample_edgelist.R b/R/sample_edgelist.R index cccac92..8675c06 100644 --- a/R/sample_edgelist.R +++ b/R/sample_edgelist.R @@ -146,7 +146,7 @@ sample_edgelist <- function( factor_model, ...) { - ellipsis::check_dots_unnamed() + rlang::check_dots_unnamed() UseMethod("sample_edgelist") } diff --git a/R/sample_igraph.R b/R/sample_igraph.R index 11a2104..c830aa3 100644 --- a/R/sample_igraph.R +++ b/R/sample_igraph.R @@ -27,15 +27,9 @@ sample_igraph <- function( factor_model, ...) { - ellipsis::check_dots_unnamed() + rlang::check_dots_unnamed() - if (!(requireNamespace("igraph", quietly = TRUE))) { - stop( - "Must install `igraph` package to return graphs as `igraph` ", - "objects", - call. = FALSE - ) - } + rlang::check_installed("igraph", "to return graphs as `igraph` objects.") UseMethod("sample_igraph") } diff --git a/R/sample_sparse.R b/R/sample_sparse.R index a63c885..0b5ec95 100644 --- a/R/sample_sparse.R +++ b/R/sample_sparse.R @@ -24,7 +24,7 @@ sample_sparse <- function( factor_model, ...) { - ellipsis::check_dots_unnamed() + rlang::check_dots_unnamed() UseMethod("sample_sparse") } diff --git a/R/sample_tidygraph.R b/R/sample_tidygraph.R index c041b35..b281af9 100644 --- a/R/sample_tidygraph.R +++ b/R/sample_tidygraph.R @@ -27,15 +27,8 @@ sample_tidygraph <- function( factor_model, ...) { - ellipsis::check_dots_unnamed() - - if (!(requireNamespace("tidygraph", quietly = TRUE))) { - stop( - "Must install `tidygraph` package to return graphs as `tidygraph` ", - "objects", - call. = FALSE - ) - } + rlang::check_dots_unnamed() + rlang::check_installed("igraph", "to return graphs as `tidygraph` objects.") UseMethod("sample_tidygraph") } diff --git a/R/undirected_factor_model.R b/R/undirected_factor_model.R index 52c09a6..3cea930 100644 --- a/R/undirected_factor_model.R +++ b/R/undirected_factor_model.R @@ -4,7 +4,7 @@ new_undirected_factor_model <- function( poisson_edges = TRUE, allow_self_loops = TRUE, subclass = character()) { - ellipsis::check_dots_unnamed() + rlang::check_dots_unnamed() n <- nrow(X) k <- ncol(S)