capture_warnings {vaccineff} | R Documentation |
This function captures the warnings generated by an
expression without printing them to the console. It returns both the
result of the expression and the captured warnings. This is useful for
avoiding warnings appearing during routines, such as an iterative process.
To suppress or "muffle" a warning, it uses invokeRestart("muffleWarning").
The new.env()
function creates a new environment that is isolated from
other environments. This allows the function to store and modify data
(in this case, warnings) without affecting the global environment or
any other environment in the R session.
capture_warnings(expr, warn_env = new.env())
expr |
An expression to evaluate. |
warn_env |
An optional environment to store the warnings. If not provided, a new environment is created. |
A list containing two elements:
result |
The result of evaluating the expression. |
warnings |
A character vector of the warnings generated during the evaluation of the expression. |