frm_find_and_replace: Recursively find and replace symbols in a language object

View source: R/utilities.R

frm_find_and_replaceR Documentation

Recursively find and replace symbols in a language object

Description

This function traverses a language object (such as an expression or call) and recursively replaces all occurrences of a specified symbol with another symbol.

Usage

frm_find_and_replace(expr, find_sym, replace_sym)

Arguments

expr

A language object (e.g., call, expression, or list of calls) to search and modify.

find_sym

A symbol (as a name) to find within expr.

replace_sym

A symbol (as a name) to replace find_sym with.

Details

Replacement happens for symbols found within calls (recursively). A expr that is itself a bare symbol equal to find_sym is returned unchanged; this is not reachable from the ancova() call site because the input is always a formula (a call).

Value

The modified language object with all instances of find_sym replaced by replace_sym.

Examples

## Not run: 
expr <- quote(a + b * c)
frm_find_and_replace(expr, as.name("b"), as.name("x"))
# Returns: a + x * c

## End(Not run)

rbmi documentation built on Oct. 15, 2026, 9:06 a.m.