tree_new: Create a syntax tree

View source: R/tree.R

tree_newR Documentation

Create a syntax tree

Description

This function takes R code as string and creates the corresponding abstract syntax tree (AST) from which we can query nodes.

Usage

tree_new(txt, file, ignore_tags = "ast-grep-ignore")

Arguments

txt

A character string of length 1 containing the code to parse. If provided, file must not be provided.

file

Path to file containing the code to parse. If provided, txt must not be provided.

ignore_tags

Character vector indicating the tags to ignore. Default is "ast-grep-ignore", meaning that any line that follows ⁠# ast-grep-ignore⁠ will be ignored in the output of ⁠node_*()⁠ functions.

Value

An abstract syntax tree containing nodes

Examples

src <- "x <- rnorm(100, mean = 2)
    any(duplicated(y))
    plot(x)
    any(duplicated(x))"

tree_new(src)

astgrepr documentation built on June 8, 2025, 11:05 a.m.