% Generated by roxygen2: do not edit by hand % Please edit documentation in R/cnd-last.R \name{last_warnings} \alias{last_warnings} \alias{last_messages} \title{Display last warnings} \usage{ last_warnings(n = NULL) last_messages(n = NULL) } \arguments{ \item{n}{How many warnings or messages to display. Defaults to all.} } \description{ \code{last_warnings()} and \code{last_messages()} return a list of all warnings and messages that occurred during the last R command. \code{\link[=global_entrace]{global_entrace()}} must be active in order to log the messages and warnings. By default the warnings and messages are printed with a simplified backtrace, like \code{\link[=last_error]{last_error()}}. Use \code{summary()} to print the conditions with a full backtrace. } \section{Examples}{ Enable backtrace capture with \code{global_entrace()}: \if{html}{\out{
}}\preformatted{global_entrace() }\if{html}{\out{
}} Signal some warnings in nested functions. The warnings inform about which function emitted a warning but they don't provide information about the call stack: \if{html}{\out{
}}\preformatted{f <- function() \{ warning("foo"); g() \} g <- function() \{ warning("bar", immediate. = TRUE); h() \} h <- function() warning("baz") f() #> Warning in g() : bar #> Warning messages: #> 1: In f() : foo #> 2: In h() : baz }\if{html}{\out{
}} Call \code{last_warnings()} to see backtraces for each of these warnings: \if{html}{\out{
}}\preformatted{last_warnings() #> [[1]] #> #> Warning in `f()`: foo #> Backtrace: #> 1. global f() #> #> [[2]] #> #> Warning in `g()`: bar #> Backtrace: #> 1. global f() #> 2. global g() #> #> [[3]] #> #> Warning in `h()`: baz #> Backtrace: #> 1. global f() #> 2. global g() #> 3. global h() }\if{html}{\out{
}} To get a full backtrace, use \code{\link[=summary]{summary()}}. In this case the full backtraces do not include more information: \if{html}{\out{
}}\preformatted{summary(last_warnings()) #> [[1]] #> #> Warning in `f()`: #> foo #> Backtrace: #> x #> 1. \\-global f() #> #> [[2]] #> #> Warning in `g()`: #> bar #> Backtrace: #> x #> 1. \\-global f() #> 2. \\-global g() #> #> [[3]] #> #> Warning in `h()`: #> baz #> Backtrace: #> x #> 1. \\-global f() #> 2. \\-global g() #> 3. \\-global h() }\if{html}{\out{
}} } \seealso{ \code{\link[=last_error]{last_error()}} }