Managing Script Results

Both Macro.Execute() and Macro.ExecuteWithArgument() methods handle R script output (spreadsheets, graphs, reports) exactly the same way as the output from SVB macros – it is routed by Statistica according to Output Manager settings, e.g., placed into a results workbook.

This approach might be sufficient for many use cases, but is not flexible enough in situations where the output from an R script is treated as an intermediate result for subsequent processing in Statistica.

For example, an SVB script implementing a custom interactive module might implement a multiple stage analysis workflow, calling into R, analyzing the results, requesting additional inputs from the user, and calling into R repeatedly with previous results as inputs. Or an SVB macro could use tabular results returned from R to produce graphs that are more expressive and flexible than what R is able to generate.

Since the items processed by the Statistica Output Manager are intended to be a final representation of analysis results, it is not trivial to access them individually for further processing – one would need to know the type of representation selected by the user (single or multiple workbooks, individual windows) and programmatically iterate through the respective set of output items (windows, workbook contents represented as a tree), searching the item of interest by name.

Macro.ExecuteNoRouteOutput([Parameters as Collection]) As StaDocCollection

This method has been added to accommodate such special use cases: R script output is not “routed” at all, so the script runs silently; all the output from the script is collected into a StaDocCollection object (standard Statistica container for documents such as spreadsheets, graphs, reports, or workbooks) that is returned as the result of script execution. It also accepts an optional Collection for parameterization.

Now SVB macro developers can easily access individual components of R script output, e.g., to extract individual cell data from spreadsheets or to create a complex graph based on multiple columns from several spreadsheets.

Example:

Dim m As Macro

Set m = Macros.Open(MacroDir & "\some.r")

 

Dim Routput As StaDocCollection

Set Routput = m.ExecuteNoRouteOutput() ' silent, no output displayed

' do something with "Routput": extract and operate on individual documents ' trivial case: results are routed (displayed), as if from Macro.Execute()

RouteOutput(Routput, "R Script Results").Visible = True