Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patch options #27

Closed
Closed
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,4 @@ rsconnect/

# dev site
dev/
inst/doc
39 changes: 22 additions & 17 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,30 +1,35 @@
Package: zephyr
Title: Tools for Informing Users Based on Package Options
Version: 0.0.5
Version: 0.0.4.9000
Authors@R: c(
person("Aksel", "Thomsen", , "[email protected]", role = c("aut", "cre")),
person("Mathias Lerbech", "Jeppesen", , "[email protected]", role = "aut"),
person("Cervan", "Girard", , "[email protected]", role = "aut"),
person("Kristian", "Troejelsgaard", ,"[email protected]", role = "aut"),
person("Kristian", "Troejelsgaard", , "[email protected]", role = "aut"),
person("Lovemore", "Gakava", , "[email protected]", role = "aut"),
person("Steffen Falgreen", "Larsen", , "[email protected]", role = "aut"),
person("Vladimir", "Obucina", , "[email protected]", role = c("aut")),
person("Novo Nordisk A/S", role = c("cph"))
person("Vladimir", "Obucina", , "[email protected]", role = "aut"),
person("Novo Nordisk A/S", role = "cph")
)
Description: Tools for helping developers of R packages inform their users.
Package enables writing messages based on package level options.
Description: Tools for helping developers of R packages inform their
users. Package enables writing messages based on package level
options.
License: Apache License (>= 2)
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.2
URL: https://novonordisk-opensource.github.io/zephyr/,
https://github.com/NovoNordisk-OpenSource/zephyr
Imports:
cli,
rlang
Suggests:
testthat (>= 3.0.0),
withr,
checkmate,
dplyr
dplyr,
glue,
knitr,
rmarkdown,
testthat (>= 3.0.0),
usethis,
withr
Config/testthat/edition: 3
URL: https://novonordisk-opensource.github.io/zephyr/, https://github.com/NovoNordisk-OpenSource/zephyr
Imports:
cli,
rlang,
utils
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.2
12 changes: 5 additions & 7 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,18 @@ export(envvar_is_true_pkg)
export(envvar_str_split_pkg)
export(get_all_verbosity_levels)
export(get_option_spec_pkg)
export(get_package_name_and_env_verbosity)
export(get_package_name_and_verbosity)
export(get_package_option)
export(get_verbosity_level)
export(msg)
export(msg_danger)
export(msg_debug)
export(msg_minimal)
export(msg_info)
export(msg_success)
export(msg_verbose)
export(msg_warning)
export(opt_pkg)
export(opt_source_pkg)
export(option_spec_pkg)
export(opts_pkg)
export(remove_option_pkg)
export(report_checkmate_assertions)
importFrom(rlang,call_name)
importFrom(rlang,call_ns)
importFrom(utils,getFromNamespace)
export(use_zephyr)
17 changes: 10 additions & 7 deletions R/checkmate.R
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
#' Report collection of assertions
#' @description
#' Improved reporting of `AssertCollections` created with the [checkmate::makeAssertCollection()] package
#' Improved reporting of `AssertCollections` created with the [checkmate::makeAssertCollection()]
#' using [cli::cli_abort()] instead of [checkmate::reportAssertions()] in order to provide a more
#' informative error message.
#'
#' The function is intended to be used inside a function that performs assertions on its input arguments.
#' See below for an example.
#' @param collection A collection of assertions created with [checkmate::makeAssertCollection()]
#' @param msg [character()] Header of the error message if any assertions failed
#' @param env [environment()] Environment to use for the error message
#' @param collection A collection of assertions created with [checkmate::makeAssertCollection()].
#' @param message `character` string with the header of the error message if any assertions failed
#' @param .envir The `environment` to use for the error message.
#' Default `parent.frame()` will be sufficient for most use cases.
#' @examples
#' add_numbers <- function(a, b) {
#' collection <- checkmate::makeAssertCollection()
Expand All @@ -24,12 +25,14 @@
#'
#' @export

report_checkmate_assertions <- function(collection, msg = "Invalid input(s):", env = parent.frame()) {
report_checkmate_assertions <- function(collection, message = "Invalid input(s):", .envir = parent.frame()) {
rlang::check_installed("checkmate")

checkmate::assert_class(collection, "AssertCollection")

if (!collection$isEmpty()) {
c(msg, rlang::set_names(collection$getMessages(), "x")) |>
cli::cli_abort(.envir = env)
c(message, rlang::set_names(collection$getMessages(), "x")) |>
cli::cli_abort(.envir = .envir)
}
invisible(TRUE)
}
Loading