Skip to content

Commit

Permalink
Wrap external examples in try() in case of missing packages
Browse files Browse the repository at this point in the history
  • Loading branch information
torfason committed Aug 26, 2023
1 parent 43155cd commit 2d0d432
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
12 changes: 6 additions & 6 deletions R/zfit_external.R
Expand Up @@ -19,7 +19,7 @@ msg_pkg_missing <- function(fun, pkg) {
#'
#' @examples
#' if (requireNamespace("estimatr") && getRversion() >= "4.1.0")
#' zlm_robust(cars, dist ~ speed) |> summary()
#' zlm_robust(cars, dist ~ speed) |> summary() |> try()
#'
#' @name zlm_robust
#' @rdname external_fitters
Expand All @@ -28,7 +28,7 @@ if (requireNamespace("estimatr", quietly = TRUE)) {
zlm_robust <- zfitter(estimatr::lm_robust)
} else {
zlm_robust <- function(...) {
warning(msg_pkg_missing("zlm_robust()", "estimatr"))
stop(msg_pkg_missing("zlm_robust()", "estimatr"))
}
}

Expand All @@ -39,7 +39,7 @@ if (requireNamespace("estimatr", quietly = TRUE)) {
#'
#' @examples
#' if (requireNamespace("MASS") && getRversion() >= "4.1.0")
#' zpolr(mtcars, ordered(gear) ~ mpg + hp) |> summary()
#' zpolr(mtcars, ordered(gear) ~ mpg + hp) |> summary() |> try()
#'
#' @name zpolr
#' @rdname external_fitters
Expand All @@ -48,7 +48,7 @@ if (requireNamespace("MASS", quietly = TRUE)) {
zpolr <- zfitter(MASS::polr)
} else {
zpolr <- function(...) {
warning(msg_pkg_missing("zpolr()", "MASS"))
stop(msg_pkg_missing("zpolr()", "MASS"))
}
}

Expand All @@ -59,7 +59,7 @@ if (requireNamespace("MASS", quietly = TRUE)) {
#'
#' @examples
#' if (requireNamespace("pls") && getRversion() >= "4.1.0")
#' zplsr(cars, dist ~ speed) |> summary()
#' zplsr(cars, dist ~ speed) |> summary() |> try()
#'
#' @name zplsr
#' @rdname external_fitters
Expand All @@ -68,6 +68,6 @@ if (requireNamespace("pls", quietly = TRUE)) {
zplsr <- zfunction(pls::plsr, x = "data", x_not_found = "ok")
} else {
zplsr <- function(...) {
warning(msg_pkg_missing("zplsr()", "pls"))
stop(msg_pkg_missing("zplsr()", "pls"))
}
}
6 changes: 3 additions & 3 deletions man/external_fitters.Rd

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

0 comments on commit 2d0d432

Please sign in to comment.