Skip to content

Commit

Permalink
Merge pull request #32 from NovoNordisk-OpenSource/feat/cran-prep
Browse files Browse the repository at this point in the history
feat: prep for CRAN
  • Loading branch information
falgreen authored Jan 16, 2025
2 parents fb557e0 + 39bfcbc commit 3a5e43e
Show file tree
Hide file tree
Showing 21 changed files with 111 additions and 29 deletions.
18 changes: 10 additions & 8 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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", , "[email protected]", role = c("aut", "cre")),
person("Mathias Lerbech", "Jeppesen", , "[email protected]", role = "aut"),
Expand All @@ -11,23 +11,25 @@ Authors@R: c(
person("Vladimir", "Obucina", , "[email protected]", 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
Expand Down
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions R/checkmate.R
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion R/msg.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
1 change: 1 addition & 0 deletions R/options.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
4 changes: 4 additions & 0 deletions R/use_zephyr.R
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down
9 changes: 9 additions & 0 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 3 additions & 13 deletions cran-comments.md
Original file line number Diff line number Diff line change
@@ -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.
1 change: 1 addition & 0 deletions inst/WORDLIST
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Aksel
BugReports
CMD
Cervan
Compats
Expand Down
3 changes: 3 additions & 0 deletions man/list_options.Rd

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

3 changes: 3 additions & 0 deletions man/report_checkmate_assertions.Rd

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

8 changes: 8 additions & 0 deletions man/use_zephyr.Rd

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

7 changes: 4 additions & 3 deletions man/zephyr-package.Rd

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

2 changes: 2 additions & 0 deletions tests/testthat/test-checkmate.R
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
39 changes: 36 additions & 3 deletions tests/testthat/test-integration.R
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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

Expand All @@ -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
Expand All @@ -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")
Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/test-msg.R
Original file line number Diff line number Diff line change
Expand Up @@ -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") |>
Expand All @@ -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") |>
Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/test-options.R
Original file line number Diff line number Diff line change
Expand Up @@ -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) |>
Expand Down
3 changes: 3 additions & 0 deletions tests/testthat/test-use_zephyr.R
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/test-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
6 changes: 6 additions & 0 deletions tests/testthat/test-verbosity_level.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
{
Expand Down Expand Up @@ -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")
})
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 3a5e43e

Please sign in to comment.