IMsRTransform.Code

Syntax

Code: String;

Description

The Code property determines expression for model calculation.

Comments

To create the expression, use R language. For more detailed description of R language see R documentation.

Example

Executing the example requires that the repository contains a modeling container with the MS identifier containing a model with the MODEL_LINEAR_R identifier. This model must be calculated by the R method. Integration with R must be set up in the repository. For details about integration setup see the How to Set Up Integration with R? section.

Add links to the Metabase and Ms system assemblies.

Sub UserProc;
Var
    mb: IMetabase;
    msKey: Integer;
    modelObj: IMetabaseObject;
    transf: IMsFormulaTransform;
    formula: IMsFormula;
    RTransform: IMsRTransform;
    inputs: IMsFormulaTermList;
    inputTerm, result: IMsRFormulaTerm;
Begin
    // Get repository
    mb := MetabaseClass.Active;
    // Get modelling container key
    msKey := mb.GetObjectKeyById("MS");
    // Get R model
    modelObj := mb.ItemByIdNamespace("MODEL_LINEAR_R", msKey).Edit;
    // Get model calculation parameters
    transf := (modelObj As IMsModel).Transform;
    formula := transf.FormulaItem(0);
    RTransform := formula.Method As IMsRTransform;
    // Get the first input variable
    inputs := RTransform.Inputs;
    inputTerm := inputs.Item(0As IMsRFormulaTerm;
    // Rename input variable
    inputTerm.Name := "a";
    // Get output variable
    result := RTransform.Result As IMsRFormulaTerm;
    // Rename output variable
    result.Name := "res";
    // Set expression for model calculation
    RTransform.Code := "res <- a + 1;";
    // Save changes
    modelObj.Save;
End Sub UserProc;

After executing the example calculation code is set for the MODEL_LINEAR_R model.

See also:

IMsRTransform | The R Model