Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

fn_body

Get or set function body


Description

fn_body() is a simple wrapper around base::body(). It always returns a \{ expression and throws an error when the input is a primitive function (whereas body() returns NULL). The setter version preserves attributes, unlike body<-.

Usage

fn_body(fn = caller_fn())

fn_body(fn) <- value

Arguments

fn

A function. It is lookep up in the calling frame if not supplied.

value

New formals or formals names for fn.

Examples

# fn_body() is like body() but always returns a block:
fn <- function() do()
body(fn)
fn_body(fn)

# It also throws an error when used on a primitive function:
try(fn_body(base::list))

rlang

Functions for Base Types and Core R and 'Tidyverse' Features

v0.4.11
MIT + file LICENSE
Authors
Lionel Henry [aut, cre], Hadley Wickham [aut], mikefc [cph] (Hash implementation based on Mike's xxhashlite), Yann Collet [cph] (Author of the embedded xxHash library), RStudio [cph]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.