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
Implement package-level quiet option #14
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# zzz.R - miscellany | ||
|
||
wtf_message <- function(...) { | ||
if (getOption("whattheflux.quiet", default = FALSE)) { | ||
return() | ||
} | ||
message(...) | ||
} | ||
|
||
wtf_warning <- function(...) { | ||
if (getOption("whattheflux.quiet", default = FALSE)) { | ||
return() | ||
} | ||
warning(...) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
test_that("quiet functionality works", { | ||
# Check that the wtf_message and wtf_warning functions respect quiet option | ||
options(whattheflux.quiet = TRUE) | ||
expect_no_message(wtf_message("hi")) | ||
expect_no_warning(wtf_warning("hi")) | ||
|
||
options(whattheflux.quiet = FALSE) | ||
expect_message(wtf_message("hi"), regexp = "hi") | ||
expect_warning(wtf_warning("hi"), regexp = "hi") | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in test files, I myself tend to use
withr::local_options()
to be sure it's reset. 😇There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @maelle ! I'm hesitant to introduce another package dependency just for this, but will consider.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
testthat itself imports withr, so it's already there, it'd just be one more line in Suggests 😇 but more seriously I completely understand, no pressure 😀