Testing TIBCO® Enterprise Runtime for R (TERR) data functions inside and outside of TIBCO Spotfire®

By:
Last updated:
11:12pm Aug 26, 2019

TIBCO® Enterprise Runtime for R (TERR) and TIBCO Spotfire® data conversions behave differently, so they can result in unexpected differences in data. 

For example, you should never have TERR read a CSV or SAS data file directly when you develop a data function, because Spotfire and the data import functions in TERR give different data types or column names.

To ensure that you get consistent results both in data functions run from Spotfire and in an interactive TERR session, import the raw data into Spotfire, and then export it from Spotfire in the SBDF format. Then read the resulting SBDF file into TERR. Make sure you use the same TERR engine in both environments.This article walks you through the task of testing a function that you intend to use in a Spotfire data function.

Recommended

Install RStudio on your computer.

Task

  1. Import the file containing your data into Spotfire.

    Often, this file is in a database, an .xls file, a .csv file, or a similar file format.
    1. From the menu, click File > Open, and browse to the data file.
    2. In the Import Settings dialog, confirm the column data types, and then click OK.

      The data is imported, and a recommended visualization is displayed.
  2. From the menu, click File > Export > Data to File

    The Export Data dialog is displayed.
  3. Select Export all rows, and then click OK.
  4. Browse to the location to store the exported data, and in the Save as type drop-down list box, select TIBCO Spotfire Binary Data Format (*.sbdf).
  5. From the menu, click Tools > TERR Tools, and then click Launch RStudio IDE.

    RStudio opens, with the configuration to run the TERR engine that is included with Spotfire.

    Alternative: You can write and test the script from the TERR console.  From the menu, click Tools > TERR Tools, and then click Launch TERR Console
  6. At the command prompt, read in the data using the following command.

    myData <- SpotfireData::importDataFromSBDF("path/to/myData.sbdf")

    where myData is the object name and path/to/myData.sbdf is the path and the name of the file you saved.

    TERR imports the data file in the same format that is used in Spotfire. (This is the same process that Spotfire uses when it loads the data in the data function.)
  7. In the RStudio IDE (or from the TERR Console), create and test the function that you plan to use in Spotfire as your data function.

    Tip:  If the data function is given zero rows of data (for example, if the data function is configured to be given only marked data, and usually initially there is no marked data), in TERR, you can test the function for that possibility by specifying the source of the data as myData[0, ]. Then testing shows all of the columns of the original data but no rows.
  8. Copy the function to use in your data function, and then close RStudio (or TERR Console).
  9. In Spotfire, register and run the new data function.
  10. If you see unexpected results when you run the data function in Spotfire, try the following.
    1. In Spotfire, at the top of the data function, add the following line of code, and then run it

      save.image("/winfolder/DataFunction.RData")

      where winfolder is the Windows folder where to store the .RData file.
    2. In RStudio, at the top of the TERR function, add the following line of code, and then run through each line of the function.

      load("/winfolder /DataFunction.RData")

      where winfolder is the Windows folder where you stored the .RData file.

      (This loads the data that the data function got from Spotfire.)

Results

When you have finished testing, you should be able to identify any differences and end up with the same results in both environments.

Examples