How to Debug a Data Function


When you write a TIBCO Enterprise Runtime for R (TERR) Data Function to add to your analysis, you can use the built-in debugging feature in Spotfire to examine the output debugging log, and you can find and fix any problems with the Data Function directly from within the Spotfire environment.

In this example, first set the option to enable debugging for Data Functions, and then run a built-in data function in a sample analysis and review the debugging output. Then introduce an error to the Data Function and review the output again to learn how Spotfire reports problems with Data Functions.

To enable debugging for Data Functions

  1. In TIBCO Spotfire, select Tools > Options.

  2. From the list, click Data Functions

  3. In the Data Functions page, select Enable Data Function debugging.

  4. Click OK to accept the change.

    Response: For any Data Function you run, Spotfire captures and displays the printed debugging output and any error that occurs.

Example 1

The following example walks you through opening a sample analysis, viewing the debugging output, and then clearing the cache.

  1. On the Authoring bar, click Files and data .

  2. In the Files and data flyout, browse the Spotfire library to open the sample analysis Sample Data Functions/TERR/TERR_PredictOnASequence_Kyphoses.
    Response: The analysis opens, and the data functions run, displaying in top right corner with a notification.

  3. Click Notifications .

    Response: The Notifications dialog is displayed, and the Alerts tab shows the following.

  4. To view the debugging output, expand the notification message.
    Response: The message displays all of the logged output.

  5. Copy the output to the clipboard, and then paste it into a text editor to view the entire message more easily. (Keep this text to compare with the next example.)

  6. After you have reviewed the output, in the Notifications dialog, click Clear, and then close the dialog.

    Response: The notifications cache is cleared and the Details warning is no longer displayed.

Example 2

The following example demonstrates introducing an error to a Data Function, and then viewing the results in the debugging notification. For this example, continue working in the sample analysis TERR_PredictOnASequence_Kyphosis.

  1. On the menu bar, select Data > Data function properties.

    Response: The Data Function Properties dialog is displayed.

  2. From the list, select TERR_PredictOnASequence, and then click Edit Script.

    Response: The Edit Script dialog is displayed.

  3. Scroll to line 9, and change the line of code to read modelVariableNames <- all.vats(if (is.R()) { .

    Comment: That is, you are changing all.vars to all.vats. This change introduces an error in the script.

  4. Save and close the erroneous script.

  5. In the Data Function Properties dialog, click Refresh.

    Response: The Details warning icon changes to an error icon and reports two notifications.

  6. Click Details.

    Response: The Notifications dialog is displayed, and the Alerts tab shows two messages: an error and a message.

  7. Click Copy to Clipboard, and then paste the results into the text editor under the results from the previous example.

    Comment: Notice that the error message indicates where the error occurred:

    TIBCO Enterprise Runtime for R returned an error: 'Error in eval(expr, envir, enclos): could not find function "all.vats"'. Also, notice that the debug output is truncated.

  8. Optional: Reopen the script, correct the previous error, and then edit it to introduce a different error further down in the script. Run the Data Function, and then examine the debugging output to see how the error is reported.

  9. Clear the cache, and then close all dialogs. Be sure to correct the broken script before you close the sample analysis.

See also:

What are Data Functions?

How to Use Data Functions

Script and Data Function Trust