pick_models: Pick models

Description Usage Arguments Value Note Examples

View source: R/utils-event.R

Description

Pick models from model and world while giving a higher priority to any model object that has the same name between the two. For example, if both have a model object called model_one, although they have totally different values, this will pick the model_one from model and not the other model_one in world. The function goes over both objects to find all models with the names in required_models.

Usage

1
pick_models(model, world, required_models, as_r6model = FALSE)

Arguments

model

logical(1)
A named list that contains models that Trans supports.

world

a World object.

required_models

character()
A character vector contains names of required models.

as_r6model

default as FALSE, if TRUE all required_models will be returned as Model objects.

Value

a list of models.

Note

This is used by event functions to prioritise which models, from the user argument or the one added to World, to use. An error will be raised if not all required models are found.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
# pick_model looks for 'model_one'
create_toy_world()
my_model <- list(model_two = list(yes = 0.1, no = 0.9))
world$add(x = list(yes = 0.5, no = 0.5), "model_one")
world$add(x = list(yes = 0.5, no = 0.5), "model_two")
REQUIRED_MODELS <- c("model_one", "model_two")
final_model <- pick_models(my_model, world, REQUIRED_MODELS)

# you can see that the final pick picked model_one from `my_model` and
# not the one that was added to world as it gives hihger priority to the object
# in `model`.
final_model

dymium-org/dymiumCore documentation built on July 18, 2021, 5:10 p.m.