Data functions are calculations based on S-PLUS, open-source R, SAS®, MATLAB® scripts*, or R scripts running under TIBCO Enterprise Runtime for R for Spotfire.
If you want to follow along, download a template here. To write your new Data Function you need to register it first. Go to Edit > Data Function Properties > Register New…
You then type your function Name and choose a Type (here I want to write an R script using TERR). You can also use R Packages – type their names separated by semicolons.
In the script area you will code your function.
You can pass a value, table or a column from Spotfire to your data function. To do that you need to set your Input Parameters. Click Add and then type your Input parameter name and select its Type (here I want to pass a Table). If you leave the Display name field blank, it will take a value of the Input parameter name. Next, select allowed data types of your input parameter and click OK.
You can always edit the script by clicking the Edit Script button in the Data Function Properties window.
To pass the outputs of your data function back to Spotfire, you need to set Output Parameters. You do it in the same way as the Input Parameters.
You can use your Parameters in the script. Here, I show a very simple example that takes my one column input table and sums up all the values into my output value parameter.
Then, you need to Save your data function.
Your new data function is now registered. To use it in your current (or any other) Spotfire Analysis you need to insert it.
After clicking the Insert button you will see all the registered functions. Pick the one you want to insert.
When you do that you will see a window that will allow you to map your Data Function parameters to the tables or document properties that are used in the Spotfire analysis. To do that you need to select the appropriate Input handler (here I’m choosing Columns as my Input Parameter is a table Type). Next, from the Data Table dropdown you need to select the Data Table you want to pass and Select Columns from that table.
A similar process applies to the Output Parameters. Here, I want to pass my Output value to a Document Property. As I don’t have that Property yet, I can create it on the spot.
Click OK and OK.
Your Data Function is ready to use.
You can either run it by clicking the Refresh button in the Document property Window or you can add a Button to your Spotfire Analysis that will run it on click (see below).
In the example below, I have displayed my Output Parameter value that is mapped to a Document Property in the label below the button.
Need examples? Check out these example Spotfire templates that use TERR:
- Random Forest Template, for purchase
- Free template deconstructing Multivariate Regression
- Another free template, but using Inline TERR to create LOWESS Smoothing
“Choose a job you love, and you will never have to work a day in your life.” -Confucius