"keep.source"
option is TRUE
, R's parser
will attach detailed information on the object it has parsed. These
functions retrieve that information.getParseData(x, includeText = NA)
getParseText(parseData, id)
parse
, or a function or other
object with source reference information
getParseData
getParseData
:
If parse data is not present, NULL
. Otherwise
a data frame is returned, containing the following columns:
"parse"
in getSrcLocation
,
which ignores #line
directives."column"
in getSrcLocation
.id
of the parent of this item.includeText
is TRUE
, the
text of all tokens; if it is NA
(the default), the text of terminal
tokens. If includeText == FALSE
, this column is not included.
Very long strings (with source of 1000 characters or more) will not be stored;
a message giving their length and delimiter will be included instead.id
values,
and the data frame will have a "srcfile"
attribute containing
the srcfile
record which was used. The rows will be
ordered by starting position within the source file, with parent items
occurring before their children. For getParseText
:
A character vector of the same length as id
containing the associated
text items. If they are not included in parseData
, they will be
retrieved from the original file.srcfile
record associated with source references in the
parsed code, and retrieved by the getParseData
function.parse
, srcref
fn <- function(x) {
x + 1 # A comment, kept as part of the source
}
d <- getParseData(fn)
if (!is.null(d)) {
plus <- which(d$token == "'+'")
sum <- d$parent[plus]
print(d[as.character(sum),])
print(getParseText(d, sum))
}
Run the code above in your browser using DataLab