Skip to content

Commit

Permalink
tweak for multiple suppress inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
philchalmers committed Aug 16, 2024
1 parent 84cffd6 commit ae1dfa8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
14 changes: 11 additions & 3 deletions R/manageWarnings.R
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,15 @@
#' fun(warn_trailing=TRUE)
#' fun(warn_trailing=TRUE)
#'
#' # does not match because string is not identical
#' # partial match, therefore suppressed
#' fun(warn_trailing=TRUE) |>
#' manageWarnings(suppress="Message with lots of random trailings: ")
#'
#' # multiple suppress strings
#' fun(warn_trailing=TRUE) |>
#' manageWarnings(suppress=c("Message with lots of random trailings: ",
#' "Suppress this too"))
#'
#' # could also use .* to catch all remaining characters (finer regex control)
#' fun(warn_trailing=TRUE) |>
#' manageWarnings(suppress="Message with lots of random trailings: .*")
Expand Down Expand Up @@ -240,8 +245,11 @@
#'
manageWarnings <- function(expr, warning2error = FALSE, suppress = NULL, ...){
stopit <- function(message, warning2error, suppress, ...){
if(!is.null(suppress))
if(grepl(suppress, message, ...)) return(TRUE)
if(!is.null(suppress)){
match_suppress <- sapply(suppress, function(supp)
grepl(supp, message, ...))
if(any(match_suppress)) return(TRUE)
}
if(is.null(warning2error)) stop(message, call.=FALSE)
sapply(warning2error, function(warn){
if(warn == "") return(invisible(NULL))
Expand Down
7 changes: 6 additions & 1 deletion man/manageWarnings.Rd

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

0 comments on commit ae1dfa8

Please sign in to comment.