Introduction for Data Function Authors


Data functions are calculations often based on R scripts running under TIBCO Enterprise Runtime for R (TERR), but they can also be based on open-source R, SAS® scripts,  MATLAB® scripts*, or S-PLUS.

Concerning R:

Open-source R is available under separate open source software license terms and is not part of TIBCO Spotfire.  As such, open-source R is not within the scope of your license for TIBCO Spotfire. Open-source R is not supported, maintained, or warranted in any way by TIBCO Software Inc. Download and use of open-source R is solely at your own discretion and subject to the free open source license terms applicable to open-source R.

See http://spotfi.re/sr for information about the TIBCO Spotfire Statistics Services system requirements.

Getting started

First, define a data function and save it to the library using the Register Data Functions dialog. Second, apply the data function to your analysis. For example, you can use a data function as a transformation step when you add or replace data tables. You can also use it as a separate tool, by opening a suitable data function using the Files and data flyout or using Insert in the Data Function Properties dialog.

You can define an S-PLUS or open-source R data function either from an existing function in the corresponding TIBCO Spotfire Statistics Services package repository, or by writing a script directly in the Register Data Functions dialog, and then running using the appropriate engine.

You can specify input and output parameters when you set up a data function.

To ensure a rapid response and a good user experience, avoid sending very large data sets from Spotfire to a statistical engine, or invoking complex, long-running calculations.

Tip: You can develop open-source R or TERR scripts in RStudio, a full-featured, open-source integrated development environment for working with R code. RStudio is provided independently of TIBCO Software Inc. You can configure RStudio to use the TERR engine, and to display its language reference. Also, you can access the TERR language reference at https://docs.tibco.com/products/tibco-enterprise-runtime-for-r.

Example 1:

A simple conversion of the values in a column from degrees Celsius to degrees Fahrenheit. Although this is easy to accomplish using the Add calculated column tool, it serves as an example simple enough to show input and output parameter handling in more detail.

To create and run an R script data function in a TERR Engine:

  1. Assume that the data table in TIBCO Spotfire contains a column with temperatures expressed in degrees Celsius.

  2. First, on the menu bar, select Tools > Register data functions.

  3. For Type, specify R script - TIBCO Enterprise Runtime for R from the drop-down list.

  4. Define the script to perform the conversion on the Script tab:

    # Define the convertTemperature function:
    convertTemperature <- function(x)
    {
      x*(9/5) + 32
    }
    # Run the function to produce the output:
    out <- convertTemperature(x);

  5. Define the input parameter x as a column with the allowed data types Integer and Real.

    Tip: You can select the parameter in the Script tab and use the pop-up menu option Input Parameter to reach the Input Parameter dialog directly.

  6. Define the output parameter out as a column.

    Tip: You can select the parameter in the Script tab and use the pop-up menu option Output Parameter to reach the Output Parameter dialog directly.

    Note that the output display name will not be propagated to the output column name. The column name is always the output specified by the R script.

  7. Save the data function to the library, as Temperature converter.

  8. To run the calculation and to connect the input and output parameters to your current data in TIBCO Spotfire, on the authoring bar, click Files and data and locate the data function of interest by searching for a suitable keyword or by browsing the different categories.

    Comment: To locate all data functions in the library, enter type:datafunction in the search field. To be able to add data functions that require a data table input, you must first have some data loaded in the analysis.

  9. In the Data Function – Select Input dialog, specify that the input parameter x  should be a column and select the data table and column to convert.

  10. Click OK.

  11. In the summary view, select how to add the new data; as a new data table or as a new column in an existing data table, and click OK when you are done.

The data function calculation is performed and a new column is added as specified. You can change the parameter settings or refresh the calculation later by selecting Data > Data functions properties.

Example 2:

If the function to use is a Principal Component Analysis (PCA) calculation, the input would be a number of numerical data columns retrieved from the current data in TIBCO Spotfire and, optionally, a parameter specifying the percent variation to be preserved by the principal components. The output would include three new data tables (scores, loadings and eigenvalue/explained variance table) and a scalar indicating the number of principal components generated.

See also:

How to Register a Data Function

How to Debug a Data Function

Details on Register Data Functions

Script and Data Function Trust

* SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration.

MATLAB is a trademark or registered trademark of The MathWorks, Inc.