diff --git a/DESCRIPTION b/DESCRIPTION index 7362fe1..5741cd8 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: zephyr -Title: Tools for Informing Users and Control Options -Version: 0.0.4.9001 +Title: Structured Messages and Options +Version: 0.0.5 Authors@R: c( person("Aksel", "Thomsen", , "oath@novonordisk.com", role = c("aut", "cre")), person("Mathias Lerbech", "Jeppesen", , "nmlj@novonordisk.com", role = "aut"), @@ -11,23 +11,25 @@ Authors@R: c( person("Vladimir", "Obucina", , "vlob@novonordisk.com", role = "aut"), person("Novo Nordisk A/S", role = "cph") ) -Description: Tools for helping developers of R packages to create consistent - messages for their users and enables a streamlined control of options - in their packages. +Description: Provides a structured framework for consistent user + communication and configuration management for package developers. License: Apache License (>= 2) URL: https://novonordisk-opensource.github.io/zephyr/, - https://github.com/NovoNordisk-OpenSource/zephyr + https://github.com/novonordisk-opensource/zephyr +BugReports: https://github.com/novonordisk-opensource/zephyr/issues +Depends: + R (>= 4.1) Imports: cli, glue, - rlang + rlang (>= 1.0.0) Suggests: callr, checkmate, devtools, knitr, rmarkdown, - testthat (>= 3.0.0), + testthat (>= 3.1.5), usethis, withr Config/testthat/edition: 3 diff --git a/LICENSE.md b/LICENSE.md index 2d17ef8..9816f63 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -179,7 +179,7 @@ recommend that a file or class name and description of purpose be included on the same “printed page” as the copyright notice for easier identification within third-party archives. - Copyright 2024 Novo Nordisk A/S, Danish company registration no. 24256790 + Copyright 2025 Novo Nordisk A/S, Danish company registration no. 24256790 Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/R/checkmate.R b/R/checkmate.R index e5ab770..fae5062 100644 --- a/R/checkmate.R +++ b/R/checkmate.R @@ -13,6 +13,7 @@ #' if any assertions failed #' @param .envir The `[environment]` to use for the error message. #' Default `parent.frame()` will be sufficient for most use cases. +#' @returns `invisible(TRUE)` #' @examples #' add_numbers <- function(a, b) { #' collection <- checkmate::makeAssertCollection() diff --git a/R/msg.R b/R/msg.R index ce93ae2..c30d4c0 100644 --- a/R/msg.R +++ b/R/msg.R @@ -36,7 +36,7 @@ #' Default `parent.frame()` will be sufficient for most use cases. Parsed on to #' `msg_fun()`. #' -#' @return Return from `msg_fun()` +#' @returns Return from `msg_fun()` #' #' @examples #' msg("General message") diff --git a/R/options.R b/R/options.R index 0f9675d..7d0fc26 100644 --- a/R/options.R +++ b/R/options.R @@ -144,6 +144,7 @@ get_option <- function(name, .envir = sys.function(which = -1)) { #' each option. #' @param .envir Environment in which the options are defined. #' Default is suitable for use inside your package. +#' @returns `list` or `character` depending on `as` #' @examples #' # List all options in zephyr #' x <- list_options(.envir = "zephyr") diff --git a/R/use_zephyr.R b/R/use_zephyr.R index 9d4c7f0..c0b9a4b 100644 --- a/R/use_zephyr.R +++ b/R/use_zephyr.R @@ -9,6 +9,10 @@ #' This code also creates an package specific `verbosity_level` option, #' enabling you to control the verbosity of your package functions using #' the [msg] functions. +#' @returns `invisible(TRUE)` +#' @examplesIf FALSE +#' use_zephyr() +#' #' @export use_zephyr <- function() { cli::cli_h1("Setting up {.pkg zephyr}") diff --git a/README.Rmd b/README.Rmd index 0cec96d..f3b73d9 100644 --- a/README.Rmd +++ b/README.Rmd @@ -39,6 +39,15 @@ For packages outside our ecosystem, we recommend using the [options](https://cran.r-project.org/package=options) package instead for a more complete implementation of package options. +## Installation + +```{r, eval=FALSE} +# Install the released version from CRAN: +install.packages("zephyr") +# Install the development version from GitHub: +pak::pak("NovoNordisk-OpenSource/zephyr") +``` + ## Use zephyr The easiest way to use zephyr in your package is to set it up with the diff --git a/README.md b/README.md index 938aafb..1cd1ec8 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,15 @@ For packages outside our ecosystem, we recommend using the [options](https://cran.r-project.org/package=options) package instead for a more complete implementation of package options. +## Installation + +``` r +# Install the released version from CRAN: +install.packages("zephyr") +# Install the development version from GitHub: +pak::pak("NovoNordisk-OpenSource/zephyr") +``` + ## Use zephyr The easiest way to use zephyr in your package is to set it up with the diff --git a/cran-comments.md b/cran-comments.md index b0623f6..62c010f 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -1,15 +1,5 @@ -## Overview -* This is a new lightweight package that provide a wrapper around the cli package as a useful way of providing messages for both users and developers when developing new functions - -* The messages can be turned on/off by utilizing environmental options which is a convenient way of controlling the level of messages for both users and developers. - -## Test Environment -* Ubuntu 18.04 LTS (on github actions), devel, release, oldrel-1 -* Windows Server 2019 (on github actions), release -* macOS (on github actions), release - - ## R CMD check results -0 errors | 0 warnings | 1 note -* This is the first submission. +0 errors | 0 warnings | 0 note + +* This is a new release. diff --git a/inst/WORDLIST b/inst/WORDLIST index cb18d8d..49a1a55 100644 --- a/inst/WORDLIST +++ b/inst/WORDLIST @@ -1,4 +1,5 @@ Aksel +BugReports CMD Cervan Compats diff --git a/man/list_options.Rd b/man/list_options.Rd index 6cfefdf..bce14d2 100644 --- a/man/list_options.Rd +++ b/man/list_options.Rd @@ -23,6 +23,9 @@ each option. \item{.envir}{Environment in which the options are defined. Default is suitable for use inside your package.} } +\value{ +\code{list} or \code{character} depending on \code{as} +} \description{ List all \code{zephyr_options} specified in a package. Either as an \code{list} or as as \code{character} vector formatted for use in your package documentation. diff --git a/man/report_checkmate_assertions.Rd b/man/report_checkmate_assertions.Rd index 8c20e3d..7719223 100644 --- a/man/report_checkmate_assertions.Rd +++ b/man/report_checkmate_assertions.Rd @@ -20,6 +20,9 @@ if any assertions failed} \item{.envir}{The \verb{[environment]} to use for the error message. Default \code{parent.frame()} will be sufficient for most use cases.} } +\value{ +\code{invisible(TRUE)} +} \description{ Improved reporting of an \code{AssertCollection} created with the \code{\link[checkmate:AssertCollection]{checkmate::makeAssertCollection()}} using \code{\link[cli:cli_abort]{cli::cli_abort()}} instead of diff --git a/man/use_zephyr.Rd b/man/use_zephyr.Rd index 0c3ca36..9b79ce3 100644 --- a/man/use_zephyr.Rd +++ b/man/use_zephyr.Rd @@ -6,6 +6,9 @@ \usage{ use_zephyr() } +\value{ +\code{invisible(TRUE)} +} \description{ Utility function to set up the use of zephyr options and \link{verbosity_level} in your package. @@ -17,3 +20,8 @@ This code also creates an package specific \code{verbosity_level} option, enabling you to control the verbosity of your package functions using the \link{msg} functions. } +\examples{ +\dontshow{if (FALSE) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +use_zephyr() +\dontshow{\}) # examplesIf} +} diff --git a/man/zephyr-package.Rd b/man/zephyr-package.Rd index 6283060..daeb3ec 100644 --- a/man/zephyr-package.Rd +++ b/man/zephyr-package.Rd @@ -4,17 +4,18 @@ \name{zephyr-package} \alias{zephyr} \alias{zephyr-package} -\title{zephyr: Tools for Informing Users and Control Options} +\title{zephyr: Structured Messages and Options} \description{ \if{html}{\figure{logo.png}{options: style='float: right' alt='logo' width='120'}} -Tools for helping developers of R packages to create consistent messages for their users and enables a streamlined control of options in their packages. +Provides a structured framework for consistent user communication and configuration management for package developers. } \seealso{ Useful links: \itemize{ \item \url{https://novonordisk-opensource.github.io/zephyr/} - \item \url{https://github.com/NovoNordisk-OpenSource/zephyr} + \item \url{https://github.com/novonordisk-opensource/zephyr} + \item Report bugs at \url{https://github.com/novonordisk-opensource/zephyr/issues} } } diff --git a/tests/testthat/test-checkmate.R b/tests/testthat/test-checkmate.R index 6142d46..2bc4c45 100644 --- a/tests/testthat/test-checkmate.R +++ b/tests/testthat/test-checkmate.R @@ -1,4 +1,6 @@ test_that("report assertions", { + skip_if_not_installed("checkmate") + add_numbers <- function(a, b) { collection <- checkmate::makeAssertCollection() checkmate::assert_numeric(x = a, add = collection) diff --git a/tests/testthat/test-integration.R b/tests/testthat/test-integration.R index f89f7da..4d19c78 100644 --- a/tests/testthat/test-integration.R +++ b/tests/testthat/test-integration.R @@ -1,6 +1,12 @@ -run_output <- function(func, extra_lib) { +run_output <- function(func, extra_lib, args = list()) { libpath <- c(extra_lib, .libPaths()) - callr::r(func = func, show = TRUE, libpath = libpath, spinner = FALSE) + callr::r( + func = func, + args = args, + show = TRUE, + libpath = libpath, + spinner = FALSE + ) } run_output_project <- function(func, extra_lib, project) { @@ -21,6 +27,9 @@ libpath <- withr::local_tempdir() test_that("integration in new package", { skip_on_cran() skip_on_covr() + skip_if_not_installed("withr") + skip_if_not_installed("usethis") + skip_if_not_installed("devtools") # Settings @@ -42,8 +51,24 @@ test_that("integration in new package", { ) # Install zephyr in tmp libpath + pkg <- file.path(test_path(), "../..") + if (file.exists(file.path(pkg, "DESCRIPTION"))) { + pkg <- "." + } else { + skip_on_os("windows") + pkg <- file.path(pkg, "zephyr") |> + normalizePath() + } - run_output(\() devtools::install(quiet = TRUE), libpath) |> + run_output( + \(p) devtools::install( # nolint: brace_linter + pkg = p, + quiet = TRUE, + quick = TRUE + ), + libpath, + list(p = pkg) + ) |> expect_true() # Use in new package @@ -69,6 +94,14 @@ test_that("integration in new package", { test_that("use in new package", { skip_on_cran() skip_on_covr() + skip_if_not_installed("withr") + skip_if_not_installed("usethis") + skip_if_not_installed("devtools") + skip_if_not_installed("callr") + skip_if( + condition = !file.exists(file.path(libpath, "testpkg")), + message = "testpkg not installed - expected if test above has been skipped" + ) run_output(\() testpkg::greet("there"), libpath) |> expect_output("hello there") diff --git a/tests/testthat/test-msg.R b/tests/testthat/test-msg.R index d880abe..a95dae7 100644 --- a/tests/testthat/test-msg.R +++ b/tests/testthat/test-msg.R @@ -22,6 +22,7 @@ test_that("Default verbosity work as intended", { }) test_that("Minimal verbosity has the expected behavior", { + skip_if_not_installed("withr") withr::local_options(list(zephyr.verbosity_level = "minimal")) msg("This gives a message for everything except quiet") |> @@ -47,6 +48,7 @@ test_that("Minimal verbosity has the expected behavior", { }) test_that("Quiet gives no messages", { + skip_if_not_installed("withr") withr::local_options(list(zephyr.verbosity_level = "quiet")) msg("This gives a message for everything except quiet") |> diff --git a/tests/testthat/test-options.R b/tests/testthat/test-options.R index 297b3f4..7f9e00f 100644 --- a/tests/testthat/test-options.R +++ b/tests/testthat/test-options.R @@ -29,6 +29,8 @@ test_that("get_option", { get_option("test_option", .envir = testenv) |> expect_equal(42, info = "Should return default when no option is set") + skip_if_not_installed("withr") + withr::local_envvar(list(R_TESTENV_TEST_OPTION = "200")) get_option("test_option", .envir = testenv) |> diff --git a/tests/testthat/test-use_zephyr.R b/tests/testthat/test-use_zephyr.R index 53209e0..dc74d56 100644 --- a/tests/testthat/test-use_zephyr.R +++ b/tests/testthat/test-use_zephyr.R @@ -1,4 +1,7 @@ test_that("use_zephyr", { + skip_if_not_installed("withr") + skip_if_not_installed("usethis") + rlang::local_interactive(FALSE) withr::local_options(usethis.quiet = TRUE) diff --git a/tests/testthat/test-utils.R b/tests/testthat/test-utils.R index 8be67e3..4aa5549 100644 --- a/tests/testthat/test-utils.R +++ b/tests/testthat/test-utils.R @@ -10,6 +10,8 @@ test_that("sys_getenv", { sys_getenv("fake_env") |> expect_null() + skip_if_not_installed("withr") + withr::with_envvar( new = list(myenv = "myvalue"), code = { diff --git a/tests/testthat/test-verbosity_level.R b/tests/testthat/test-verbosity_level.R index 4e6e9de..45e4e74 100644 --- a/tests/testthat/test-verbosity_level.R +++ b/tests/testthat/test-verbosity_level.R @@ -2,6 +2,8 @@ test_that("simple verbosity level", { get_verbosity_level() |> expect_equal("verbose") + skip_if_not_installed("withr") + withr::with_options( list(zephyr.verbosity_level = "invalid"), { @@ -49,6 +51,8 @@ test_that("verbosity level respects priority hierarchy when used in package", { expect_equal(get_verbosity_level(test_env), "verbose") # Test 2: Package-specific option (highest priority) + skip_if_not_installed("withr") + withr::with_options(list(testpkg.verbosity_level = "debug"), { expect_equal(get_verbosity_level(test_env), "debug") }) @@ -112,6 +116,8 @@ test_that("get_all_verbosity_levels", { get_all_verbosity_levels() |> expect_equal(c(zephyr = "verbose")) + skip_if_not_installed("withr") + withr::with_namespace(c("cli", "glue"), { withr::local_options(list( zephyr.verbosity_level = "quiet",