The R Project SVN R

Rev

Rev 68055 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
54801 ripley 1
% File src/library/utils/man/sourceutils.Rd
68948 ripley 2
% Part of the R package, https://www.R-project.org
64657 ripley 3
% Copyright 2011-2013 R Core Team
54801 ripley 4
% Distributed under GPL 2 or later
5
 
6
\name{sourceutils}
7
\alias{getSrcFilename}
8
\alias{getSrcDirectory}
9
\alias{getSrcref}
10
\alias{getSrcLocation}
11
\title{
12
  Source Reference Utilities
13
}
14
\description{
15
  These functions extract information from source references.
16
}
17
\usage{
18
getSrcFilename(x, full.names = FALSE, unique = TRUE)
61433 ripley 19
getSrcDirectory(x, unique = TRUE)
54801 ripley 20
getSrcref(x)
56280 ripley 21
getSrcLocation(x, which = c("line", "column", "byte", "parse"),
22
               first = TRUE)
54801 ripley 23
}
24
\arguments{
25
  \item{x}{
26
    An object (typically a function) containing source references.
27
  }
28
  \item{full.names}{
29
    Whether to include the full path in the filename result.
30
  }
31
  \item{unique}{
32
    Whether to list only unique filenames/directories.
33
  }
34
  \item{which}{
68055 ripley 35
    Which part of a source reference to extract.  Can be abbreviated.
54801 ripley 36
  }
37
  \item{first}{
38
    Whether to show the first (or last) location of the object.
39
  }
40
}
41
\details{
61650 murdoch 42
  Each statement of a function will have its own source reference if the 
62070 hornik 43
  \code{"keep.source"} option is \code{TRUE}.  These functions retrieve
44
  all of them. 
54801 ripley 45
 
46
  The components are as follows:
47
  \describe{
48
    \item{line}{The line number where the object starts or ends.}
49
    \item{column}{The column number where the object starts or ends.}
50
    \item{byte}{As for \code{"column"}, but counting bytes, which may
51
      differ in case of multibyte characters.}
52
    \item{parse}{As for \code{"line"}, but this ignores \code{#line} directives.}
53
  }
54
}
55
\value{
61433 ripley 56
  \code{getSrcFilename} and \code{getSrcDirectory} return character vectors
54801 ripley 57
  holding the filename/directory.
58
 
59
  \code{getSrcref} returns a list of \code{"srcref"} objects or
60
  \code{NULL} if there are none.
61
 
62
  \code{getSrcLocation} returns an integer vector of the requested type
63
  of locations.
64
}
65
\seealso{
59883 murdoch 66
\code{\link{srcref}}, \code{\link{getParseData}}
54801 ripley 67
}
68
\examples{
69
fn <- function(x) {
70
  x + 1 # A comment, kept as part of the source
61433 ripley 71
}			
54801 ripley 72
 
73
# Show the temporary file directory
74
# where the example was saved
75
 
61433 ripley 76
getSrcDirectory(fn)
54801 ripley 77
getSrcLocation(fn, "line")
78
}
79
\keyword{ utilities }