propegate_values: Partially evaluate a code block with given variable values

Description Usage Arguments Value Examples

Description

Partially evaluate a code block with given variable values

Usage

1
propegate_values(code, ..., dots = list(), envir = NULL)

Arguments

code

the code block to use as the basis for evaluation

...

named variables and values to be evaluated within the code

dots

optionally specify additional ellipses names as list

envir

the environment in which subtrees should be evaluated. If missing (the default) an environment as a direct child of the base environment is created with only declarations of the ellipses arguments and used for evaluation of the tree.

Value

the input code block with specified variables partially applied

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
codeblock <- quote({
  # inserting values into a code block
  my_function_1 <- function() {
    print(paste(input$a, input$b, other_var))
  }

  my_function_2 <- function() {
    print(input$a)
    print(input$b)
  }
  
  # example of behavior when a value is not present
  my_function_2 <- function() {
    print(input$c + other_var)
  }
  
  # example of variable getting declared in a local frame
  my_function_3 <- function() {
    input <- 3
    print(input)
  }
  
  # example of a variable getting declared in a parent frame
  input <- 4
  my_function_4 <- function() {
    print(input)
  }
})


codeblock <- quote({
  output$test <- function() { print("a") }
  output$test()
})

scriptgloss:::propegate_values(
    codeblock, 
    input = list(
      a = list(1, 2, 3, 4), 
      b = "b"))

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