Returning Free-form Text from Statistics Services


We have shown in earlier posts how to execute Data Functions from within Spotfire using TIBCO Spotfire Statistics Services to return values, columns, and Data Tables,  and we have also shown how to return binary objects like images.

There are also lots of times where the analysis in S+ or R will produce additional text, and it would make since in some analysis files to display this information back in Spotfire.

This can be accomplished with some code added into your Data Function.  This code will ask for a text summary of a given object you want information on.  In this example, the object is analysis.lm

# Capture S+ summary of the regression as 'summary.table'
mytmp = tempfile()
sink(mytmp)
print(summary(analysis.lm))
sink()
file.r.con = open(mytmp, mode="r")
summary.table = readLines(file.r.con, n=-1)
close(file.r.con)
unlink(mytmp)



We can then hook this up into Spotfire as a Data Table. In this example the Data Table is called summary.table.
 


Once the Data Function executes, the summary text will be displayed as a single column inside a Spotfire Data Table as shown below.

 



We can then edit the Properties of the Data Table to not display gridlines and use Courier fonts so that all the content aligns.

 



The Data Function can also be combined with other capabilities, like returning other Data Tables and images.