Movatterモバイル変換


[0]ホーム

URL:


debug {base}R Documentation

Debug a Function

Description

Set, unset or query the debugging flag on a function.Thetext andcondition arguments are the same as thosethat can be supplied via a call tobrowser. They can be retrievedby the user once the browser has been entered, and provide a mechanism toallow users to identify which breakpoint has been activated.

Usage

debug(fun, text = "", condition = NULL, signature = NULL)debugonce(fun, text = "", condition = NULL, signature = NULL)undebug(fun, signature = NULL)isdebugged(fun, signature = NULL)debuggingState(on = NULL)

Arguments

fun

any interpretedR function or a character string namingone.

text

a text string that can be retrieved when the browser is entered.

condition

a condition that can be retrieved when the browser isentered.

signature

an optional method signature. If specified, themethod is debugged, rather than its generic.

on

logical; a call to the support functiondebuggingState returnsTRUE if debugging is globallyturned on,FALSE otherwise. An argument of one or the otherof those values sets the state. If the debugging state isFALSE, none of the debugging actions will occur (but explicitbrowser calls in functions will continue to work).

Details

When a function flagged for debugging is entered, normal executionis suspended and the body of function is executed one statement at atime. A newbrowser context is initiated for each step(and the previous one destroyed).

At the debug prompt the user can enter commands orR expressions,followed by a newline. The commands are described in thebrowser help topic.

To debug a function which is defined inside another function,single-step through to the end of its definition, and then calldebug on its name.

If you want to debug a function not starting at the very beginning,usetrace(..., at = *) orsetBreakpoint.

Usingdebug is persistent, and unless debugging is turned offthe debugger will be entered on every invocation (note that if thefunction is removed and replaced the debug state is not preserved).Usedebugonce() to enter the debugger only the next time thefunction is invoked.

To debug an S4 method by explicit signature, usesignature. When specified, signature indicates the method offun to be debugged. Note that debugging is implemented slightlydifferently for this case, as it uses the trace machinery, rather thanthe debugging bit. As such,text andcondition cannot bespecified in combination with a non-nullsignature. For methodswhich implement the.local rematching mechanism, the.local closure itself is the one that will be ultimatelydebugged (seeisRematched).

isdebugged returnsTRUE if a)signature isNULLand the closurefun has been debugged, or b)signature is notNULL,fun is an S4 generic, and the method offunfor that signature has been debugged. In all other cases, it returnsFALSE.

The number of lines printed for the deparsed call when a function isentered for debugging can be limited by settingoptions(deparse.max.lines).

When debugging is enabled on a byte compiled function then theinterpreted version of the function will be used until debugging isdisabled.

Value

debug andundebug invisibly returnNULL.

isdebugged returnsTRUE if the function or method is

marked for debugging, andFALSE otherwise.

See Also

debugcall for conveniently debugging methods,browser notably for its ‘commands’,trace;traceback to see the stack after anError: ...message;recover for another debugging approach.

Examples

## Not run: debug(library)library(methods)## End(Not run)## Not run: debugonce(sample)## only the first call will be debuggedsample(10, 1)sample(10, 1)## End(Not run)

[Packagebase version 4.6.0Index]

[8]ページ先頭

©2009-2025 Movatter.jp