Analyse the Parse Tree of an R Script
Arguments
- x
parse tree as returned by
parse
- path
for internal use only (when this function is called recursively)
Examples
# Parse an R script file (here, a file from kwb.utils)
x <- parse("https://raw.githubusercontent.com/KWB-R/kwb.utils/master/R/log.R")
# Analyse the parse tree (This may take some time!)
result <- kwb.code::analyse(x)
# Show the structure of the result list (only 3 levels!)
str(result, 3)
#> List of 11
#> $ type : chr "expression"
#> $ mode : chr "expression"
#> $ class : chr "expression"
#> $ length : int 4
#> $ text : chr "[1].log <- function(...) {\n ..."
#> $ is : chr [1:3] "expression" "language" "recursive"
#> $ n_modes : int 1
#> $ n_classes: int 1
#> $ fulltype : chr "expression|expression|expression|4|expression,language,recursive"
#> $ path : chr ""
#> $ children :List of 4
#> ..$ :List of 11
#> .. ..$ type : chr "language"
#> .. ..$ mode : chr "call"
#> .. ..$ class : chr "<-"
#> .. ..$ length : int 3
#> .. ..$ text : chr "[1]<-[2].log[3]function(...) { ..."
#> .. ..$ is : chr [1:3] "call" "language" "recursive"
#> .. ..$ n_modes : int 1
#> .. ..$ n_classes: int 1
#> .. ..$ fulltype : chr "language|call|<-|3|call,language,recursive"
#> .. ..$ path : chr "/1"
#> .. ..$ children :List of 3
#> ..$ :List of 11
#> .. ..$ type : chr "language"
#> .. ..$ mode : chr "call"
#> .. ..$ class : chr "<-"
#> .. ..$ length : int 3
#> .. ..$ text : chr "[1]<-[2].logline[3]function(.. ..."
#> .. ..$ is : chr [1:3] "call" "language" "recursive"
#> .. ..$ n_modes : int 1
#> .. ..$ n_classes: int 1
#> .. ..$ fulltype : chr "language|call|<-|3|call,language,recursive"
#> .. ..$ path : chr "/2"
#> .. ..$ children :List of 3
#> ..$ :List of 11
#> .. ..$ type : chr "language"
#> .. ..$ mode : chr "call"
#> .. ..$ class : chr "<-"
#> .. ..$ length : int 3
#> .. ..$ text : chr "[1]<-[2].logok[3]function(dbg ..."
#> .. ..$ is : chr [1:3] "call" "language" "recursive"
#> .. ..$ n_modes : int 1
#> .. ..$ n_classes: int 1
#> .. ..$ fulltype : chr "language|call|<-|3|call,language,recursive"
#> .. ..$ path : chr "/3"
#> .. ..$ children :List of 3
#> ..$ :List of 11
#> .. ..$ type : chr "language"
#> .. ..$ mode : chr "call"
#> .. ..$ class : chr "<-"
#> .. ..$ length : int 3
#> .. ..$ text : chr "[1]<-[2].logstart[3]function(d ..."
#> .. ..$ is : chr [1:3] "call" "language" "recursive"
#> .. ..$ n_modes : int 1
#> .. ..$ n_classes: int 1
#> .. ..$ fulltype : chr "language|call|<-|3|call,language,recursive"
#> .. ..$ path : chr "/4"
#> .. ..$ children :List of 3