Skip to contents

Extract Sections of Same "Type" from Parse Tree

Usage

get_elements_by_type(x, result = NULL, dbg = TRUE)

Arguments

x

parse tree as returned by parse

result

optional. Result as returned by analyse

dbg

if TRUE, debug messages are shown

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")

# For each "type" of code segment, extract all occurrences
elements <- get_elements_by_type(x)
#> Analysing the parse tree ... ok. (0.19 secs) 

# Show all for-loops
elements$`language|call|for|4|`
#> NULL

# Show all if-statements
elements$`language|call|if|3|`
#> NULL

# Show all if-else-statements
elements$`language|call|if|4|`
#> NULL