The R Project SVN R

Rev

Rev 59039 | Rev 66751 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 59039 Rev 61150
Line 110... Line 110...
110
  expression (such as returned by a call to \code{\link{quote}} or
110
  expression (such as returned by a call to \code{\link{quote}} or
111
  \code{\link{substitute}}).  This expression itself is inserted in the
111
  \code{\link{substitute}}).  This expression itself is inserted in the
112
  traced function, so it will typically involve arguments or local
112
  traced function, so it will typically involve arguments or local
113
  objects in the traced function.  An expression of this form is useful
113
  objects in the traced function.  An expression of this form is useful
114
  if you only want to interact when certain conditions apply (and in
114
  if you only want to interact when certain conditions apply (and in
115
  this case you probably want to supply \code{print=FALSE} in the call
115
  this case you probably want to supply \code{print = FALSE} in the call
116
  to \code{trace} also).
116
  to \code{trace} also).
117
 
117
 
118
  When the \code{at} argument is supplied, it can be a vector of
118
  When the \code{at} argument is supplied, it can be a vector of
119
  integers referring to the substeps of the body of the function (this
119
  integers referring to the substeps of the body of the function (this
120
  only works if the body of the function is enclosed in \code{{ ...}}.  In
120
  only works if the body of the function is enclosed in \code{{ ...}}.  In
Line 148... Line 148...
148
  \code{untrace} on the same function or method in between, the
148
  \code{untrace} on the same function or method in between, the
149
  previously edited version is retained.  If you want to throw away
149
  previously edited version is retained.  If you want to throw away
150
  all the previous tracing and then edit, call \code{untrace} before the next
150
  all the previous tracing and then edit, call \code{untrace} before the next
151
  call to \code{trace}.  Editing may be combined with automatic
151
  call to \code{trace}.  Editing may be combined with automatic
152
  tracing; just supply the other arguments such as \code{tracer}, and
152
  tracing; just supply the other arguments such as \code{tracer}, and
153
  the \code{edit} argument as well.  The \code{edit=TRUE} argument
153
  the \code{edit} argument as well.  The \code{edit = TRUE} argument
154
  uses the default editor (see \code{\link{edit}}).
154
  uses the default editor (see \code{\link{edit}}).
155
 
155
 
156
  Tracing primitive functions (builtins and specials) from the base
156
  Tracing primitive functions (builtins and specials) from the base
157
  package works, but only by a special mechanism and not very
157
  package works, but only by a special mechanism and not very
158
  informatively.  Tracing a primitive causes the primitive to be
158
  informatively.  Tracing a primitive causes the primitive to be
Line 227... Line 227...
227
    if (x > 0) x ^ y else stop("x must be positive")
227
    if (x > 0) x ^ y else stop("x must be positive")
228
}
228
}
229
 
229
 
230
## arrange to call the browser on entering and exiting
230
## arrange to call the browser on entering and exiting
231
## function f
231
## function f
232
trace("f", quote(browser(skipCalls=4)),
232
trace("f", quote(browser(skipCalls = 4)),
233
      exit = quote(browser(skipCalls=4)))
233
      exit = quote(browser(skipCalls = 4)))
234
 
234
 
235
## instead, conditionally assign some data, and then browse
235
## instead, conditionally assign some data, and then browse
236
## on exit, but only then.  Don't bother me otherwise
236
## on exit, but only then.  Don't bother me otherwise
237
 
237
 
238
trace("f", quote(if(any(y < 0)) yOrig <- y),
238
trace("f", quote(if(any(y < 0)) yOrig <- y),
239
      exit = quote(if(exists("yOrig")) browser(skipCalls=4)),
239
      exit = quote(if(exists("yOrig")) browser(skipCalls = 4)),
240
      print = FALSE)
240
      print = FALSE)
241
 
241
 
242
## Enter the browser just before stop() is called.  First, find
242
## Enter the browser just before stop() is called.  First, find
243
## the step numbers
243
## the step numbers
244
 
244
 
245
as.list(body(f))
245
as.list(body(f))
246
as.list(body(f)[[3]])
246
as.list(body(f)[[3]])
247
 
247
 
248
## Now call the browser there
248
## Now call the browser there
249
 
249
 
250
trace("f", quote(browser(skipCalls=4)), at=list(c(3,4)))
250
trace("f", quote(browser(skipCalls = 4)), at = list(c(3,4)))
251
 
251
 
252
## trace a utility function, with recover so we
252
## trace a utility function, with recover so we
253
## can browse in the calling functions as well.
253
## can browse in the calling functions as well.
254
 
254
 
255
trace("as.matrix", recover)
255
trace("as.matrix", recover)