R parser package on CRAN
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
The parser package has been released to CRAN, the package mainly defines a function parser that is similar to the usual R function parse, with the few following differences:
- The information about the location of each token is structured differently, in a data frame
- location is gathered for all symbols from the source code, including terminal symbols (tokens), comments
- An equal sign is identified to be either an assignment, the declaration of a formal argument or the use of an argument
Here is an example file containing R source code that we are going to parse with parser
#' a roxygen comment f <- function( x = 3 ){ # a regular comment rnorm(10 ) + runif( 10 ) }
It is a very simple file, for illustration purpose. Let's look what to do with it with the parser package
The parser generates a list of expressions, just like the regular parse function, but the gain is the data
attribute. This is a data frame where each token of the parse tree is a line. The id column identifies each line, and the parent column identifies the parent of the current line.
At the moment, only the forthcoming highlight package uses the parser package (actually the parser package has been factored out of highlight), but some anticipated uses of the package include:
- rework the codetools package so that it tells source location of potential problems
- code coverage in RUnit or svUnit
- rework the roxygen parser
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.