The R Project SVN R

Rev

Rev 68948 | 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
80665 kalibera 3
% Copyright 2011-2021 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.}
80665 kalibera 49
    \item{column}{The column number where the object starts or ends.
50
      Horizontal tabs are converted to spaces.}
54801 ripley 51
    \item{byte}{As for \code{"column"}, but counting bytes, which may
80665 kalibera 52
      differ in case of multibyte characters (and horizontal tabs).}
54801 ripley 53
    \item{parse}{As for \code{"line"}, but this ignores \code{#line} directives.}
54
  }
55
}
56
\value{
61433 ripley 57
  \code{getSrcFilename} and \code{getSrcDirectory} return character vectors
54801 ripley 58
  holding the filename/directory.
59
 
60
  \code{getSrcref} returns a list of \code{"srcref"} objects or
61
  \code{NULL} if there are none.
62
 
63
  \code{getSrcLocation} returns an integer vector of the requested type
64
  of locations.
65
}
66
\seealso{
59883 murdoch 67
\code{\link{srcref}}, \code{\link{getParseData}}
54801 ripley 68
}
69
\examples{
70
fn <- function(x) {
71
  x + 1 # A comment, kept as part of the source
61433 ripley 72
}			
54801 ripley 73
 
74
# Show the temporary file directory
75
# where the example was saved
76
 
61433 ripley 77
getSrcDirectory(fn)
54801 ripley 78
getSrcLocation(fn, "line")
79
}
80
\keyword{ utilities }