Extract Sections of Same "Type" from Parse Tree
Source:R/get_elements_by_type.R
get_elements_by_type.Rd
Extract Sections of Same "Type" from Parse Tree
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