get_elements_by_type: Extract Sections of Same "Type" from Parse Tree

View source: R/get_elements_by_type.R

get_elements_by_typeR Documentation

Extract Sections of Same "Type" from Parse Tree

Description

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)

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

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

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


KWB-R/kwb.code documentation built on July 28, 2023, 5:57 p.m.