getParseData
Get Detailed Parse Information from Object

Description

Given a parsed expression, produce a data.frame containing detailed information about the parsed expression, including comments.

Usage

getParseData(x, includeText = NA)
getParseText(parseData, id)

Arguments

x A parsed expression, as returned by parse. The parsing must be done with the keep.source argument equal to TRUE, to keep the parsing information used by getParseData.
includeText A logical value.
parseData A data.frame returned by getParseData.
id A vector of integers.

Details

The includeText argument specifies whether the data.frame produced by getParseData contains the text for each of the parsed tokens.
Value
getParseDatareturns a data.frame with one row for each of the tokens in the parsed expression. The data.frame columns are the following:

  • "line1" Line number of the first character of the token text.
  • "col1" Column number of the first character of the token text.
  • "line2" Line number of the last character of the token text.
  • "col2" Column number of the last character of the token text.
  • "id" An integer identifying the token.
  • "parent" The ID of the parent token of this token.
  • "token" S string giving the token type.
  • "terminal" A logical value, TRUE if the token has no children.
  • "text" The text string for this token. If the includeText argument is FALSE, this column is not present.
getParseTextreturns a vector of strings, giving the token strings corresponding to the specified ID numbers.
See Also
parse.
Examples
ex <- parse(text="#comm1\nx<-function(x) {\n#comm2\n  x+1\n}\n",
            keep.source=TRUE)
pd <- getParseData(ex)
#    line1 col1 line2 col2 id parent          token terminal     text
# 1      1    1     1    6  1      0        COMMENT     TRUE   #comm1
# 20     2    1     5    1 20      0           expr    FALSE
# 3      2    1     2    1  3      4         SYMBOL     TRUE        x
# ...

getParseText(pd, 1) # [1] "#comm1"

Package utils version 6.1.4-13
Package Index