Find the Location of a Line of Source Code, or Set a Breakpoint There.
These functions locate objects containing particular lines of source
code, using the information saved when the code was parsed with
keep.source = TRUE.
findLineNum(srcfile, line, nameonly = TRUE, envir = parent.frame(), lastenv)
setBreakpoint(srcfile, line, nameonly = TRUE, envir = parent.frame(), lastenv, verbose = TRUE, tracer, print = FALSE, clear = FALSE, ...)
- The name of the file containing the source code.
- The line number within the file. See Details for an alternate way to specify this.
TRUE(the default), we require only a match to
basename(srcfile), not to the full path.
- Where do we start looking for function objects?
- Where do we stop? See the Details.
- Should we print information on where breakpoints were set?
- An optional
tracerfunction to pass to
trace. By default, a call to
- Additional arguments to pass to
findLineNum function searches through all objects in
envir, its parent, grandparent, etc., all the way
lastenv defaults to the global environment if
envir is not specified, and to the
specified. (The first default tends to be quite fast, and will
usually find all user code other than S4 methods; the second one is
quite slow, as it will typically search all attached system
envir may be specified indirectly: if it is
not an environment, it will be replaced with
srcfile is normally a filename entered as a character
string, but it may be a
"srcfile" object, or it may
include a suffix like
"filename.R#nn", in which case the number
nn will be used as a default value for
As described in the description of the
where argument on the
man page for
trace, the Rpackage system uses a
complicated scheme that may include more than one copy of a function
in a package. The user will typically see the public one on the
search path, while code in the package will see a private one in the
package namespace. If you set
envir to the environment of a
function in the package, by default
findLineNum will find both
setBreakpoint will set the breakpoint in both.
(This can be controlled using
envir = environment(foo),
lastenv = globalenv()
will find only the private copy, as the search is stopped before
seeing the public copy.)
S version 4 methods are also somewhat tricky to find. They are stored
with the generic function, which may be in the
lastenv = emptyenv()
in order to find them. In some cases transformations are done by Rwhen storing them and
findLineNum may not be able to find the
original code. Many special cases, e.g.
# Find what function was defined in the file mysource.R at line 100: findLineNum("mysource.R#100") # Set a breakpoint in both copies of that function, assuming one is in the # same namespace as myfunction and the other is on the search path setBreakpoint("mysource.R#100", envir = myfunction)