model_do: Call a function in a model object

Description Usage model_do See Also Examples

Description

In the CAB package, models are implemented in CAB.model child classes. The model child classes contain slots that hold functions that are necessary for the model. The model child classes also contain a slot called organism that contains all the parameters that are necessary for the model. The model_do function calls specific model functions and automatically finds their parameters in the organism slot.

Usage

1
model_do(model, fx_name)

model_do

For calling functions in a CAB.model object.

Usage

model_do(model, fx_name)

Arguments

model

A CAB.model object.

fx_name

A name of a model function. This refers to the slot in the CAB.model object, not the name of the function as it is in the global environment.

Value

Returns the value that the associated function returns. If a parameter in organism is changed, use o_set to assign it.

See Also

class.CAB.model o_set also for the example

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# Carrying on from the example in class.CAB.models:
good_times_model

# Take our initial value of "happiness_level" to be 100
# Use the plus_happy function in the "plus_happy" slot to add 10 to the happiness
new_happiness = model_do( good_times_model, "plus_happy" )
new_happiness
# Change the model value
o_set( good_times_model, "happiness_level", new_happiness, i = 1 )
# Check the new value
good_times_model

Don-Li/CAB documentation built on May 6, 2019, 2:52 p.m.