The Main.R file

1 Running a simulation

The whole simulation can be ran from one file, provided it has been properly configurated

1.1 Basic info

Running a simulation calls upon the Main.R script. This file is pre-formatted, and found at the root of the R project folder.

To open the script, either locate it in the file structure or use the following command :

file.edit("Main.R")

A copy of the Main.R file can be created if you wish to save the original version or pre-configure multiple simulation runs. This copy must also be placed at the root of the R project folder.

new_file_name <- "Main_personalised.R"
file.copy(from = "Main.R", to = new_file_name)
file.edit(new_file_name)

To quickly run a simulation that has been properly calibrated, simply select all lines and run them through a ctrl + enter or without selecting source the script by pressing ctrl + shift + S

1.2 Understanding the Main.R script structure

Main.R script is built on four steps.

1.2.1 Step 0: Setup

The Setup step resets the R environment, loads the necessary libraries and custom functions. It also reads the simulation configurations (input and output) into an R list object. All configuration parameters can be accessed in the config list.

## 0. Setup
rm(list = ls())
source(file.path("src","setup.R"))


  config <- readconfig(input_config_file = file.path("configuration", "config_input_threeme.R") ,
                      output_config_file = file.path("configuration", "config_output_threeme.R")
                     )

1.2.2 Step 1: Calibration bubble

The calibration bubble step is optional, it is by default deactivated, but reactivated by decommenting the lines if need be. See the calibration page for more info.

## 1. OPTIONAL Prepare the baseline and/or shock calibration file , uncomment the lines

# ## >>>>>>> uncomment start
# calibration_bubble <- calibration_environment(baseline_calibration = FALSE)
# list2env(calibration_bubble, envir = globalenv())
# ### You may now open the relevant scenario config file to edit and test it
# rm(list = names(calibration_bubble))
# ## <<<<<<< uncomment end

1.2.3 Step 2: Run simulations

Step 2 runs the simulations based on the configuration specified in Step 0. It consists in one line of code :

data_full <- run_simulations(configuration = config)

This function runs all the necessary steps to simulate the model, including reading and interpretaing .mdl blocks, launching the solver. It returns a database containing simulation results of the baseline and shocks specified in configuration input. For more information on the data_full database, see this page .

1.2.4 Step 3: Produce selected result templates

Step 3 (Optional) will run predefined quarto templates to explore simulation results. The templates to be used are chosen and specified in the output configuration step.

## 3. Produce results via quarto templates

produce_quartos(Show = TRUE)
# cleanup_output() # 

Activating the Show argument by selecting TRUE will display automatically the results in your web browser after they are rendered.

1.2.5 Step 4: Render your own quarto document

Step 4 is also optional. It contains the line to render a user-made quarto file to view and analyze your results.

## 4. Run your own quarto here

# quarto::quarto_render("wp.qmd")

In order to use it :

  • create, edit and save your own .qmd file (ie my_quarto.qmd). Save it at the root of the folder
  • replace wp.qmd by my_quarto.qmd in the script line
  • execute the line to render the file.
  • the rendered output is found in the results/quarto_render folder.