Movatterモバイル変換


[0]ホーム

URL:


rdrr.io

traceback: Get and Print Call Stacks

tracebackR Documentation

Get and Print Call Stacks

Description

By defaulttraceback() prints the call stack of the lastuncaught error, i.e., the sequence of calls that lead to the error.This is useful when an error occurs with an unidentifiable errormessage. It can also be used to print the current stack orarbitrary lists of calls.

.traceback() nowreturns the above call stack (andtraceback(x, *) can be regarded as convenience function forprinting the result of.traceback(x)).

Usage

 traceback(x = NULL, max.lines = getOption("traceback.max.lines",                                           getOption("deparse.max.lines", -1L))).traceback(x = NULL, max.lines = getOption("traceback.max.lines",                                           getOption("deparse.max.lines", -1L)))

Arguments

x

NULL (default, meaning.Traceback), or aninteger count of calls to skip in the current stack, or a list orpairlist of calls. See the details.

max.lines

a number, the maximum number of lines to be printedper call. The default is unlimited. Applies only whenxisNULL, alist or apairlist ofcalls, see the details.

Details

The default display is of the stack of the last uncaught error asstored as a list ofcalls in.Traceback, whichtraceback prints in a user-friendly format. The stack ofcalls always contains all function calls and all foreignfunction calls (such as.Call): if profiling is inprogress it will include calls to some primitive functions. (Callsto builtins are included, but not to specials.)

Errors which are caughtviatry ortryCatch do not generate a traceback, so what is printedis the call sequence for the last uncaught error, and not necessarilyfor the last error.

Ifx is numeric, then the current stack is printed, skippingx entries at the top of the stack. For example,options(error = function() traceback(3)) will print the stackat the time of the error, skipping the call totraceback() and.traceback()and the error function that called it.

Otherwise,x is assumed to be a list or pairlist of calls ordeparsed calls and will be displayed in the same way.

.traceback() and by extensiontraceback() may triggerdeparsing ofcalls. This is an expensive operationfor large calls so it may be advisable to setmax.linesto a reasonable value when such calls are on the call stack.

Value

.traceback() returns the deparsed call stack deepest callfirst as a list or pairlist. The number of lines deparsed fromthe call can be limited viamax.lines. Calls for whichmax.lines results in truncated output will gain a"truncated" attribute.

traceback() formats, prints, and returns the call stackproduced by.traceback() invisibly.

Warning

It is undocumented where.Traceback is stored nor that it isvisible, and this is subject to change. As ofR 4.0.0.Traceback contains thecalls as languageobjects, whereas previously these calls were deparsed.

References

Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988)The New S Language.Wadsworth & Brooks/Cole.

Examples

foo <- function(x) { print(1); bar(2) }bar <- function(x) { x + a.variable.which.does.not.exist }## Not run: foo(2) # gives a strange errortraceback()## End(Not run)## 2: bar(2)## 1: foo(2)bar## Ah, this is the culprit ...## This will print the stack trace at the time of the error.options(error = function() traceback(3))

What can we improve?

R Package Documentation

Browse R Packages

We want your feedback!

Note that we can't provide technical support on individual packages. You should contact the package authors for that.

 
Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, readEmbedding Snippets.

Close

[8]ページ先頭

©2009-2026 Movatter.jp