RSetVar()

Stores the content of the passed parameter as an R variable.

Synopsis

RSetVar( const string var, const anytype val, int userData= 0);

Parameters

Parameter Description
var Variable to be set.
val

Value to be set to the R variable. The following types are supported:

BIT, INT, FLOAT, TIME, TEXT, BLOB.

userData

Optional parameter. Context in which error occurred.You can call an R control extension function with the int parameter "userData". This value is stored in the error context structure regardless if an error occurred or not. By passing a unique userData, values are passed to chained R control extension functions and the function where an error occurred can be identified afterwards.

If -1 is passed, the last error context, which was set by a previous function where no error occurred, is not changed.

Return Value

Error status value (0 .. no error)

Description

Stores the content of the passed parameter as an R variable.

Example

The example stores the content of the passed parameters (
"var1", "var2")
as an R variable via the RSetVar function and calls the REvalExpVar function.
#uses "CtrlR"
main()
{
  dyn_float var1 = makeDynFloat(31,31,33,32,34,33,32,35,29,34,38,40,37,38,36,36,36,39,38,40,35,32,34,32,34,29,29,28,31,28,30,34,33,28,31,32,33,33,33,35,36,36,40,38,40,37,40,38,40,38);
  dyn_float var2 =  makeDynFloat(401,381,382,392,406,372,361,405,392,399,350,342,346,354,304,345,320,317,356,323,386,406,405,396,400,401,365,400,391,398,362,368,363,373,389,370,406,386,402,367,379,380,406,389,374,379,399,406,377,407);
  RSetVar("var1", var1); /* the content of var 1 (see above) is saved in the var1 R variable */
  RSetVar("var2", var2); /* the content of var 2 (see above) is saved in the var2 R variable */
  string err_desc;
  int userData;
  string H_LINE = "***************************************************************************";
  /* Function call REvalExpVar()->Evaluates an R expression (correlation) and sets the result value for the R variable "cResult" */
  int rv = REvalExpVar(0, "cResult", "cor(%var%,%var%)", var1,
  var2);
  if (RGetLastErr(err_desc, userData, true) != 0) //error handling via the RGetLastErr function
  {
    DebugTN("Error occurred: " + err_desc);
  }
  else
  { 
    DebugN("REvalExpVar_test finished! Return value:", rv);
    anytype at = RGetVar("cResult");
    DebugN("Value of the R variable cResult:", at);
    DebugN(H_LINE);
  }
}

Assignment

R Functions

Availability

R Control Extension

See also

RGetVar()