| 49825 |
ripley |
1 |
% File src/library/utils/man/findLineNum.Rd
|
|
|
2 |
% Part of the R package, http://www.R-project.org
|
| 59039 |
ripley |
3 |
% Copyright 2009 Duncan Murdoch and the R Core Team
|
| 49825 |
ripley |
4 |
% Distributed under GPL 2 or later
|
|
|
5 |
|
|
|
6 |
\name{findLineNum}
|
| 56186 |
murdoch |
7 |
\alias{findLineNum}
|
| 49825 |
ripley |
8 |
\alias{setBreakpoint}
|
|
|
9 |
\title{
|
|
|
10 |
Find the Location of a Line of Source Code, or Set a Breakpoint There.
|
|
|
11 |
}
|
|
|
12 |
\description{
|
|
|
13 |
These functions locate objects containing particular lines of source
|
|
|
14 |
code, using the information saved when the code was parsed with
|
| 61650 |
murdoch |
15 |
\code{keep.source = TRUE}.
|
| 49825 |
ripley |
16 |
}
|
|
|
17 |
\usage{
|
| 56280 |
ripley |
18 |
findLineNum(srcfile, line, nameonly = TRUE,
|
|
|
19 |
envir = parent.frame(), lastenv)
|
| 49825 |
ripley |
20 |
|
| 56280 |
ripley |
21 |
setBreakpoint(srcfile, line, nameonly = TRUE,
|
|
|
22 |
envir = parent.frame(), lastenv, verbose = TRUE,
|
| 56461 |
murdoch |
23 |
tracer, print = FALSE, clear = FALSE, ...)
|
| 49825 |
ripley |
24 |
}
|
|
|
25 |
\arguments{
|
|
|
26 |
\item{srcfile}{The name of the file containing the source code.}
|
|
|
27 |
\item{line}{The line number within the file. See Details for an
|
| 61433 |
ripley |
28 |
alternate way to specify this.}
|
| 49825 |
ripley |
29 |
\item{nameonly}{If \code{TRUE} (the default), we require only a match
|
| 61433 |
ripley |
30 |
to \code{basename(srcfile)}, not to the full path.}
|
| 49825 |
ripley |
31 |
\item{envir}{Where do we start looking for function objects?}
|
|
|
32 |
\item{lastenv}{Where do we stop? See the Details.}
|
|
|
33 |
\item{verbose}{Should we print information on where breakpoints were set?}
|
|
|
34 |
\item{tracer}{An optional \code{tracer} function to pass to
|
|
|
35 |
\code{\link{trace}}. By default, a call to \code{\link{browser}}
|
| 61433 |
ripley |
36 |
is inserted.}
|
| 49825 |
ripley |
37 |
\item{print}{The \code{print} argument to pass to \code{\link{trace}}.}
|
| 61433 |
ripley |
38 |
\item{clear}{If \code{TRUE}, call \code{\link{untrace}} rather than
|
| 56461 |
murdoch |
39 |
\code{\link{trace}}.}
|
| 49825 |
ripley |
40 |
\item{\dots}{Additional arguments to pass to \code{\link{trace}}.}
|
|
|
41 |
}
|
|
|
42 |
|
|
|
43 |
\details{
|
|
|
44 |
The \code{findLineNum} function searches through all objects in
|
| 61013 |
murdoch |
45 |
environment \code{envir}, its parent, grandparent, etc., all the way
|
| 49825 |
ripley |
46 |
back to \code{lastenv}.
|
|
|
47 |
|
|
|
48 |
\code{lastenv} defaults to the global environment if
|
| 50253 |
murdoch |
49 |
\code{envir} is not specified, and to the
|
| 49825 |
ripley |
50 |
root environment \code{\link{emptyenv}()} if \code{envir} is
|
|
|
51 |
specified. (The first default tends to be quite fast, and will
|
|
|
52 |
usually find all user code other than S4 methods; the second one is
|
|
|
53 |
quite slow, as it will typically search all attached system
|
|
|
54 |
libraries.)
|
| 61433 |
ripley |
55 |
|
| 56352 |
murdoch |
56 |
For convenience, \code{envir} may be specified indirectly: if it is
|
|
|
57 |
not an environment, it will be replaced with
|
|
|
58 |
\code{environment(envir)}.
|
| 49825 |
ripley |
59 |
|
|
|
60 |
\code{setBreakpoint} is a simple wrapper function for
|
| 56461 |
murdoch |
61 |
\code{\link{trace}} and \code{\link{untrace}}. It will set or clear
|
|
|
62 |
breakpoints at the locations found by \code{findLineNum}.
|
| 49825 |
ripley |
63 |
|
|
|
64 |
The \code{srcfile} is normally a filename entered as a character
|
|
|
65 |
string, but it may be a \code{"\link{srcfile}"} object, or it may
|
|
|
66 |
include a suffix like \code{"filename.R#nn"}, in which case the number
|
|
|
67 |
\code{nn} will be used as a default value for \code{line}.
|
|
|
68 |
|
|
|
69 |
As described in the description of the \code{where} argument on the
|
|
|
70 |
man page for \code{\link{trace}}, the \R package system uses a
|
|
|
71 |
complicated scheme that may include more than one copy of a function
|
|
|
72 |
in a package. The user will typically see the public one on the
|
|
|
73 |
search path, while code in the package will see a private one in the
|
|
|
74 |
package NAMESPACE. If you set \code{envir} to the environment of a
|
|
|
75 |
function in the package, by default \code{findLineNum} will find both
|
|
|
76 |
versions, and \code{setBreakpoint} will set the breakpoint in both.
|
| 61160 |
ripley |
77 |
(This can be controlled using \code{lastenv}; e.g. \code{envir =
|
|
|
78 |
environment(foo)}, \code{lastenv = globalenv()} will find only the
|
|
|
79 |
private copy, as the search is stopped before seeing the public copy.)
|
| 49825 |
ripley |
80 |
|
|
|
81 |
S version 4 methods are also somewhat tricky to find. They are stored
|
|
|
82 |
with the generic function, which may be in the \pkg{base} or other
|
| 61160 |
ripley |
83 |
package, so it is usually necessary to have \code{lastenv = emptyenv()}
|
| 49825 |
ripley |
84 |
in order to find them. In some cases transformations are done by \R
|
|
|
85 |
when storing them and \code{findLineNum} may not be able to find the
|
|
|
86 |
original code. Many special cases, e.g. methods on primitive
|
|
|
87 |
generics, are not yet supported.
|
|
|
88 |
}
|
|
|
89 |
\value{
|
|
|
90 |
\code{fineLineNum} returns a list of objects containing location
|
|
|
91 |
information. A \code{print} method is defined for them.
|
|
|
92 |
|
|
|
93 |
\code{setBreakpoint} has no useful return value; it is called for the
|
| 56461 |
murdoch |
94 |
side effect of calling \code{\link{trace}} or \code{\link{untrace}}.
|
| 49825 |
ripley |
95 |
}
|
|
|
96 |
\author{
|
|
|
97 |
Duncan Murdoch
|
|
|
98 |
}
|
|
|
99 |
\seealso{
|
|
|
100 |
\code{\link{trace}}
|
|
|
101 |
}
|
|
|
102 |
\examples{
|
|
|
103 |
\dontrun{
|
|
|
104 |
# Find what function was defined in the file mysource.R at line 100:
|
|
|
105 |
findLineNum("mysource.R#100")
|
|
|
106 |
|
|
|
107 |
# Set a breakpoint in both copies of that function, assuming one is in the
|
|
|
108 |
# same namespace as myfunction and the other is on the search path
|
| 61160 |
ripley |
109 |
setBreakpoint("mysource.R#100", envir = myfunction)
|
| 49825 |
ripley |
110 |
}
|
|
|
111 |
}
|
|
|
112 |
\keyword{ debugging }
|