replace_top_level_assignments: Replace top level assignments

Description Usage Arguments Value Examples

Description

Replace top level assignments

Usage

1
replace_top_level_assignments(code, from_func, to_func)

Arguments

code

list of expressions to modify or quoted code block

from_func

a function accepting a single argument, the top level expression, which will return TRUE if top level assignment expression should be modified by to_func

to_func

a function accepting a single argument, the expression being assigned to, defining how a top level assignment expression should be modified

Value

modified code block as a list of top level expressions

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
q <- quote({
  a <- list()
  a$first <- "1st!"
  untouched <- 1
  a$second <- "2nd!"
  untouched <- 2
  a
})

scriptgloss:::replace_top_level_assignments(
  q, 
  function(i) is.call(i) && length(i) >= 3 && i[[1]] == quote(a$a)[[1]],
  function(i) as.name(sprintf(
    "__%s__%s__", 
    as.character(i[[2]]), 
    as.character(i[[3]])))
)

dgkf/scriptgloss documentation built on June 8, 2019, 8:43 p.m.