Skip to content

Commit

Permalink
Use rlang::check_installed() to install missing packages on the fly.
Browse files Browse the repository at this point in the history
  • Loading branch information
olivroy committed Jul 2, 2024
1 parent fd3d993 commit ef6224d
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 32 deletions.
21 changes: 3 additions & 18 deletions R/expected-spectra.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,7 @@ eigs_sym.undirected_factor_model <- function(
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))

Expand All @@ -50,12 +45,7 @@ svds.undirected_factor_model <- function(
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))
Expand Down Expand Up @@ -95,12 +85,7 @@ svds.directed_factor_model <- function(
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))
Expand Down
8 changes: 1 addition & 7 deletions R/sample_igraph.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,7 @@ sample_igraph <- function(

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")
}
Expand Down
8 changes: 1 addition & 7 deletions R/sample_tidygraph.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,7 @@ sample_tidygraph <- function(

rlang::check_dots_unnamed()

if (!(requireNamespace("tidygraph", quietly = TRUE))) {
stop(
"Must install `tidygraph` package to return graphs as `tidygraph` ",
"objects",
call. = FALSE
)
}
rlang::check_installed("igraph", "to return graphs as `tidygraph` objects.")

UseMethod("sample_tidygraph")
}
Expand Down

0 comments on commit ef6224d

Please sign in to comment.