eval | R Documentation |
Evaluate G3 formulas / code outside a model
g3_eval(f, ...)
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. |
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:
The global g3_env
is in the environment, so functions such as avoid_zero
can be used
If substituting a g3_stock
, all definitions such as stock__minlen
will also be substituted
g3_param('x')
will pull param.x
from the environment
Result of evaluating f.
# Evaluate suitiability function for given stocks
g3_eval(
g3_suitability_andersen(0,1,2,3,4),
predator_length = 100,
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)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.