Learn R Programming

utils (version 3.5.2)

sourceutils: Source Reference Utilities

Description

These functions extract information from source references.

Usage

getSrcFilename(x, full.names = FALSE, unique = TRUE)
getSrcDirectory(x, unique = TRUE)
getSrcref(x)
getSrcLocation(x, which = c("line", "column", "byte", "parse"),
               first = TRUE)

Arguments

x

An object (typically a function) containing source references.

full.names

Whether to include the full path in the filename result.

unique

Whether to list only unique filenames/directories.

which

Which part of a source reference to extract. Can be abbreviated.

first

Whether to show the first (or last) location of the object.

Value

getSrcFilename and getSrcDirectory return character vectors holding the filename/directory.

getSrcref returns a list of "srcref" objects or NULL if there are none.

getSrcLocation returns an integer vector of the requested type of locations.

Details

Each statement of a function will have its own source reference if the "keep.source" option is TRUE. These functions retrieve all of them.

The components are as follows:

line

The line number where the object starts or ends.

column

The column number where the object starts or ends.

byte

As for "column", but counting bytes, which may differ in case of multibyte characters.

parse

As for "line", but this ignores #line directives.

See Also

srcref, getParseData

Examples

Run this code
# NOT RUN {
fn <- function(x) {
  x + 1 # A comment, kept as part of the source
}			

# Show the temporary file directory
# where the example was saved

getSrcDirectory(fn)
getSrcLocation(fn, "line")
# }

Run the code above in your browser using DataLab