The Code Editor page allows you to create R scripts that will be executed prior to running your model. This functionality can be used to define functions called within formulas elsewhere in your model, or to perform estimation tasks, such as running a regression analysis on data from the Tables page. Any variables assigned within the context of scripts can be referenced in formulas elsewhere in your model.
The scripts included within your model are shown in the menu on the left. To view a given script, simply click on the script’s name and it will be displayed in the Editor Panel on the right. Buttons are provided to the right of the name of each to allow you to delete or rename it. Scripts can be dragged up or down using the drag handles, which allow you to change the order in which they are displayed.
To create a new table, click the “Add New Table” button in the toolbar, enter a variable name for the table in the pop-up menu, and click “Add Table”.
In the Editor Panel, the contents of the script will be displayed with full syntax highlighting and can be edited. To execute the script, click the “Run Code” button. The results of the script will be shown in the Preview Panel, to the right of the Editor Panel.
The Preview Panel will show each line of code with syntax highlighting, followed by the output that it produced. Tables and plots can be shown in the Preview Panel by using the Print R function. The contents of the Display Panel can be further annotated and formatted using a special syntax referred to as R-Markdown.
R-Markdown works by mixing into the code special comments that are interpreted as formatted text. To create an R-Markdown comment on a given line, start it with two pound symbols, followed by a space (i.e. “## “). A list of markdown comment types and their effects is provided below.
Please note that scripts are not editable in View-Only Mode.