modify_lang: Recursively modify a language object

Description Usage Arguments Examples

View source: R/modify-lang.r

Description

Recursively modify a language object

Usage

1

Arguments

x

object to modify: should be a call, expression, function or list of the above.

f

function to apply to leaves

...

other arguments passed to f

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
a_to_b <- function(x) {
  if (is.name(x) && identical(x, quote(a))) return(quote(b))
  x
}
examples <- list(
  quote(a <- 5),
  alist(a = 1, c = a),
  function(a = 1) a * 10,
  expression(a <- 1, a, f(a), f(a = a))
)
modify_lang(examples, a_to_b)
# Modifies all objects called a, but doesn't modify arguments named a

pryr documentation built on Feb. 18, 2018, 9:02 a.m.