EVOLUTION-MANAGER
Edit File: r_session_debug.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Interactive debugging of persistent R sessions</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for r_session_debug {callr}"><tr><td>r_session_debug {callr}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Interactive debugging of persistent R sessions</h2> <h3>Description</h3> <p>The <code>r_session$debug()</code> method is an interactive debugger to inspect the stack of the background process after an error. </p> <h3>Details</h3> <p>Note that on callr version 3.8.0 and above, you need to set the <code>callr.traceback</code> option to <code>TRUE</code> (in the main process) to make the subprocess dump the frames on error. This is because saving the frames can be costly for large objects passed as arguments. </p> <p><code style="white-space: pre;">$debug()</code> starts a REPL (Read-Eval-Print-Loop), that evaluates R expressions in the subprocess. It is similar to <code><a href="../../base/html/browser.html">browser()</a></code> and <code><a href="../../utils/html/debugger.html">debugger()</a></code> and also has some extra commands: </p> <ul> <li> <p><code>.help</code> prints a short help message. </p> </li> <li> <p><code>.where</code> prints the complete stack trace of the error. (The same as the <code style="white-space: pre;">$traceback()</code> method. </p> </li> <li> <p><code style="white-space: pre;">.inspect <n></code> switches the "focus" to frame <code style="white-space: pre;"><n></code>. Frame 0 is the global environment, so <code style="white-space: pre;">.inspect 0</code> will switch back to that. </p> </li></ul> <p>To exit the debugger, press the usual interrupt key, i.e. <code>CTRL+c</code> or <code>ESC</code> in some GUIs. </p> <p>Here is an example session that uses <code style="white-space: pre;">$debug()</code> (some output is omitted for brevity): </p> <div class="sourceCode"><pre># ---------------------------------------------------------------------- > rs <- r_session$new() > rs$run(function() knitr::knit("no-such-file")) Error in rs_run(self, private, func, args) : callr subprocess failed: cannot open the connection > rs$debug() Debugging in process 87361, press CTRL+C (ESC) to quit. Commands: .where -- print stack trace .inspect <n> -- inspect a frame, 0 resets to .GlobalEnv .help -- print this message <cmd> -- run <cmd> in frame or .GlobalEnv 3: file(con, "r") 2: readLines(input2, encoding = "UTF-8", warn = FALSE) 1: knitr::knit("no-such-file") at #1 RS 87361 > .inspect 1 RS 87361 (frame 1) > ls() [1] "encoding" "envir" "ext" "in.file" "input" "input.dir" [7] "input2" "ocode" "oconc" "oenvir" "oopts" "optc" [13] "optk" "otangle" "out.purl" "output" "quiet" "tangle" [19] "text" RS 87361 (frame 1) > input [1] "no-such-file" RS 87361 (frame 1) > file.exists(input) [1] FALSE RS 87361 (frame 1) > # <CTRL + C> # ---------------------------------------------------------------------- </pre></div> <hr /><div style="text-align: center;">[Package <em>callr</em> version 3.7.2 <a href="00Index.html">Index</a>]</div> </body></html>