R Scripts are Statistica Macros

In most cases, Statistica treats R scripts in the same way as native SVB macros. This applies to the Statistica Object Model as well: Macro objects in SVB programs can now represent R scripts. Therefore, R scripts can be created, opened, edited, saved, and executed from within SVB scripts.

This in turn means that R functionality is available in Statistica Enterprise analysis configurations and Statistica Workspace nodes since they are SVB-based.

Existing R script files can be opened with Macros.Open(“path\to\some.r”) or created on-the-fly with Macros.New() and Macro.Code. Note that in the latter case, Statistica needs help in distinguishing R scripts from SVB macros – this can be achieved either by specifying the name for a new macro with the .R extension (even if you are not going to save it on disk), or by explicitly setting Macro.Scripting to 5 (R Macro Type). Run the scripts by calling Macro.Execute.

Important: The Macro.Scripting type for R scripts is 5 (later will be mapped to a symbolic constant).

Example:

Sub Main
Dim R As New Macro
R.Code = "ActiveDataSet"  ' simple R script created on-the-fly R.Scripting = 5	' R Macro Type = 5
R.Execute End Sub

This Statistica Visual Basic macro runs a simple R script containing only a single command ActiveDataSet which, as described in the previous section, is an R language extension for Statistica that will transfer (and in this case display) the currently active Statistica data file in R. For example, if you run this macro after opening the example data file Exp.sta, a listing of that file will be displayed in a report window that represents the R console session: