Skip to contents

This function will be called after an instance is built. User input will be stored in the environment. Any simple expressions can be provided, as long as all the symbols exist in the current environment. Note that this function tries to evaluate ALL the atomic symbols in the expression during initialization, and store the values in the object. Hence, calls like a$b will also be decomposed as $, a and b, where b will be interpreted as a variable "b" exists in the current environment. Therefore, use ~a[["b"]] instead of ~a$b. And pre-define function like myfun = function() 1, then use it in the expression ~myfun().

Random variables will be replaced by their returns of the gen method, which are typically vectors.

Inner closed form expressions in a hierarchical closed form expression will also be replaced by the returns of their gen method.

Arguments

expr

Formula. Only the right hand side of the last ~ will be kept as the final expression.

Value

Return the object itself.

Examples


# Constant variable
a <- 1

# Random uniform variable
b <- rand_uniform()

# Define a closed form expression
cf <- closed_form(~3 * (exp(a) + b))

cf
#> 
#> ── <CLOSED_FORM object>
#> EXPR = 3 * (exp(a) + b)
#>  - b: <RAND_UNIFORM object>
#>    [a: 0, b: 1] 

d <- rand_normal()

# Define a closed form expression with another closed form expression
cf2 <- closed_form(~cf + 3 * d)

cf2
#> 
#> ── <CLOSED_FORM object>
#> EXPR = cf + 3 * d
#>  - cf: <CLOSED_FORM object>
#>    EXPR = 3 * (exp(a) + b)
#>     - b: <RAND_UNIFORM object>
#>       [a: 0, b: 1]
#>  - d: <RAND_NORMAL object>
#>    [mu: 0, sigma: 1]