tailr (version 0.1.0)

user_transform: Apply user transformations depths-first.

Description

Apply user transformations depths-first.

Usage

user_transform(expr, env = rlang::caller_env())

Arguments

expr

The expression to transform -- typically a function body.

env

The environment where functions can be found.

Value

Rewritten expression

Examples

Run this code
# NOT RUN {
my_if_else <- function(test, if_true, if_false) {
    if (test) if_true else if_false
}
class(my_if_else) <- c("my_if_else", class(my_if_else))
transform_call.my_if_else <- function(fun, expr) {
    test <- expr[[2]]; if_true <- expr[[3]]; if_false <- expr[[4]]
    rlang::expr(if (rlang::UQ(test)) rlang::UQ(if_true) else rlang::UQ(if_false))
}

f <- function(x, y) my_if_else(x == y, x, f(y, y))
user_transform(body(f))

# }

Run the code above in your browser using DataLab