How to Debug a Data Function


When you write a data function using Spotfire® Enterprise Runtime for R (a/k/a TERR™) or a Python data function, 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 following examples, you first enable debugging for data functions, then you run a built-in data function in a sample analysis and review the debugging output. Finally, you 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 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 notifications.

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

  2. In the Files and data flyout, browse the Spotfire library (or use search) to open the sample analysis Library/Sample Data Functions/TERR/TERR_PredictOnASequence_Kyphosis.
    Response: The analysis opens, and the data functions run. A notification (either a pop-up or just the warning indication on the icon) is shown in the top right corner.

  3. Click Notifications  .

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

  5. If desired, you can copy the debug output to clipboard and paste it in a text editor.

  6. After you have reviewed the output, close the details dialog and click Dismiss in the Notifications panel to get rid of the message.

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 authoring bar, click Data canvas .

  2. From the list of data functions in the top left drop-down list, select TERR_PredictOnASequence.

  3. On the fx node, click Edit script.

  4. 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.

  5. Save and close the erroneous script.

  6. At the top of the data canvas, click Refresh.

    Response: The Notification icon changes to an error icon and the notifications now shows two new messages: an error and an information.

  7. Click the error notification to see details.

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

    Spotfire Enterprise Runtime for R returned an error

    The data function 'TERR_PredictOnASequence' could not be executed.

    Error in withCallingHandlers({

        fittedModel <- BlobToSObject(Fitte : could not find function "all.vats"

        eval(script, envir = .GlobalEnv)

        eval(script, envir = .GlobalEnv)

        withCallingHandlers({
    Also, you can click on the warning notification to view the debug output and notice that the debug output is truncated compared to the debug output in Example 1, without any errors.

  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 new error is reported.

  9. Close all dialogs and click Dismiss All in the Notifications panel to remove all messages. Be sure to correct the broken script before you close the sample analysis.

See also:

What are Data Functions?

How to Use Data Functions

Manage Trust