12 Deploying the model
12.1 Overview
ems_deploy() consolidates all user inputs and carries out all operations necessary to run a CGE model. It accumulates and validates data and model inputs, processes shocks and closure swaps, and writes all required input files to disk. The output file path serves as a required input to ems_solve().
12.2 Arguments
| Argument | Default | Description |
|---|---|---|
.data |
A list of data.tables generated by ems_data() |
|
model |
A tibble generated by ems_model() |
|
shock |
NULL |
A shock object or list of shock objects produced by ems_uniform_shock(), ems_custom_shock(), or ems_scenario_shock(). When NULL, a null shock is carried out which effectively returns base data |
swap_in |
NULL |
Character vector, ems_swap() object, or a list of any combination. Variables to be made exogenous |
swap_out |
NULL |
Character vector, ems_swap() object, or a list of any combination. Variables to be made endogenous |
write_dir |
tools::R_user_dir("teems", "cache") |
Base directory where the “teems” subdirectory will be created for input files and model solution |
shock_file |
NULL |
Path to a CSV representing a final shock file. No checks or modifications will be conducted on this file |
12.3 Basic usage
The simplest deployment requires only data and model inputs. With no shock supplied, a null shock is carried out:
cmf_path <- ems_deploy(
.data = .data,
model = model
)12.4 Deploying with shocks and swaps
A single shock can be passed directly:
shock <- ems_uniform_shock(var = "pop", value = 1)
cmf_path <- ems_deploy(
.data = .data,
model = model,
shock = shock
)Multiple shocks are combined in a list:
pop_shk <- ems_uniform_shock(var = "pop", value = 1)
aoall_shk <- ems_custom_shock(var = "aoall", input = aoall_df)
cmf_path <- ems_deploy(
.data = .data,
model = model,
shock = list(pop_shk, aoall_shk)
)12.5 Closure swaps
Full variable swaps can be passed as strings. Partial swaps use ems_swap() objects. These can be mixed in a list:
# Full variable swap (strings)
cmf_path <- ems_deploy(
.data = .data,
model = model,
shock = shock,
swap_in = "qfd",
swap_out = "tfd"
)
# Mixed partial and full swaps
qfd <- ems_swap(var = "qfd", REGs = "usa", PROD_COMMj = "crops")
tfd <- ems_swap(var = "tfd", REGr = "usa", PROD_COMMj = "crops")
cmf_path <- ems_deploy(
.data = .data,
model = model,
shock = list(partial, full),
swap_in = list(qfd, "yp"),
swap_out = list(tfd, "dppriv")
)12.6 User generated inputs
ems_deploy() allows for user-generated shock files via the shock_file argument. In the case of shock files, no checks or operations will be conducted (i.e., the shock file as loaded is considered the final input). User-supplied closure files will however be processed if swaps are supplied.
12.7 Persistent files
Good practice in R dictates that a user’s machine state is not modified. In order to comply with this guidance, teems will only write to temporary folders associated with the teems package and these files will be removed upon closure of the session or loading of a subsequent model. If persistent data is desired, users must provide a path to a local directory via write_dir:
cmf_path <- ems_deploy(
write_dir = "~/my_project/output",
.data = .data,
model = model,
shock = shock
)