astr

knitr::opts_chunk$set(
  warning = FALSE,
  message = FALSE,
  collapse = TRUE,
  comment = "#>"
)

R-check codecov.io

Decompose and Recompose Functions

Install

remotes::install_github("sckott/astr")
library("astr")

decompose

a simple function

foo <- function(x) {
  x + 1
}
foo(5)

decompose the function

df <- ast_decompose(foo)
df
class(df)

modify

modify an aspect of the function

out <- ast_modify(df, from = "+", to = "-")
out

recompose

ast_recompose(out)
ex <- ast_recompose(out, as_expr = TRUE)
eval(ex)(5)

Meta



sckott/astr documentation built on Nov. 12, 2024, 4:19 p.m.