Code: String;
Code: string;
The Code property determines expression for model calculation.
To create the expression, use R language. For more detailed description of R language see R documentation.
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, 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(0) As 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.
The requirements and result of the Fore.NET example execution match with those in the Fore example.
Imports Prognoz.Platform.Interop.Ms;
…
Public Shared Sub Main(Params: StartParams);
Var
mb: IMetabase;
msKey: uinteger;
modelObj: IMetabaseObject;
transf: IMsFormulaTransform;
formula: IMsFormula;
RTransform: IMsRTransform;
inputs: IMsFormulaTermList;
inputTerm, result: IMsRFormulaTerm;
Begin
// Get repository
mb := Params.Metabase;
// 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[0] As IMsRFormulaTerm;
// Rename output 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;
See also:
IMsRTransform | The R Model