eval {gadget3}R Documentation

Evaluate G3 forumulas

Description

Evaluate G3 formulas / code outside a model

Usage

g3_eval(f, ...)

Arguments

f

A formula object or quoted code to be evaluated

...

Named items to add to the formula's environment, or a single list / environment to use.

Details

Allows snippets of gadget3 code to be run outside a model. This could be done with regular eval, however, g3_eval does a number of things first:

  1. The global g3_env is in the environment, so functions such as avoid_zero can be used

  2. If substituting a g3_stock, all definitions such as stock__minlen will also be substituted

  3. g3_param('x') will pull param.x from the environment

Value

Result of evaluating f.

Examples

# Evaluate suitiability function for given stocks
g3_eval(
    g3_suitability_andersen(0,1,2,3,4),
    predstock = g3_stock('pred', 11:20),
    stock = g3_stock('prey', 1:10))

# Parameters can be filled in with "param." items in environment
g3_eval(quote( g3_param('x') ), param.x = 88)
g3_eval(
    g3_parameterized('lln.alpha', by_stock = TRUE, value = 99),
    stock = g3_stock("fish", 1:10),
    param.fish.lln.alpha = 123)

# Graph gadget3's built-in logspace_add()
if (interactive()) {
  curve(g3_eval(quote( logspace_add(a, 10) ), a = x), 0, 50)
}


[Package gadget3 version 0.11-1 Index]