body_replace {factory}R Documentation

Replace Parts of a Function Body

Description

Replace quoted targets in the body of a function with quoted replacements.

Usage

body_replace(fn_body, target, replacement)

Arguments

fn_body

The body of a function (as found via body(fun)).

target

A quoted expression to replace.

replacement

A quoted expression with which the target should be replaced.

Value

A function body with the target replaced anywhere it occurs.

Examples

fun <- function(x) {
  x^exp
}
body_replace(body(fun), quote(exp), quote(!!exp))

[Package factory version 0.1.0 Index]