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") Base directory where the “teems” subdirectory will be created for input files and model solution
shock_file NULL Path to a .shf 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 = dat,
  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 = dat,
  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 = dat,
  model = model,
  shock = list(pop_shk, aoall_shk)
)

12.5 Closure swaps

A single full variable swap swaps one variable in and one out using plain strings:

shock <- ems_uniform_shock(var = "qfd", value = 1)

cmf_path <- ems_deploy(
  .data    = dat,
  model    = model,
  shock    = shock,
  swap_in  = "qfd",
  swap_out = "tfd"
)

Multiple full variable swaps are passed as character vectors. Partial swaps use ems_swap() objects and can be mixed with strings in a list:

# Multiple full variable swaps
cmf_path <- ems_deploy(
  .data    = dat,
  model    = model,
  shock    = shock,
  swap_in  = c("qfd", "yp"),
  swap_out = c("tfd", "dppriv")
)

# Mixed partial and full swaps
yp_row     <- ems_swap("yp",     REGr = "row")
dppriv_row <- ems_swap("dppriv", REGr = "row")

cmf_path <- ems_deploy(
  .data = dat,
  model = model,
  shock = shock,
  swap_in  = list(yp_row, "qfd"),
  swap_out = list(dppriv_row, "tfd")
)

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 (output of tools::R_user_dir("teems")) and these files will be removed upon loading an new R session. If persistent data is desired, users must provide a path to a local directory via write_dir:

cmf_path <- ems_deploy(
  .data = dat,
  model = model,
  shock = shock,
  write_dir = "~/my_project/output"
)