How to Register a Data Function


You can use data functions to enhance the functionality of Spotfire. Below are a few examples of where and how data functions can be defined and applied. Note that you can use the local Spotfire® Enterprise Runtime for R (a/k/a TERR™) engine, or you can specify a TERR service, if it is deployed on a node available to your Spotfire Server. When using Python scripts you can either use a local python.exe or a Python service on the server. To use open source R, use the Spotfire Service for R. See also What are Data Functions? and Introduction for Data Function Authors.

To register a data function in Spotfire:

This example shows how to register a TERR data function, but you would use the same procedure to register data functions using other calculation engines.

  1. In Spotfire, on the menu bar, select Tools > Register data functions.

    Response: The Register Data Functions dialog is displayed.

  2. From the Type drop-down list, select the type of script to use, for example R script - Spotfire Enterprise Runtime for R.

  3. Optionally, if you want to include a predefined function from a statistical package, in the Packages field, type the exact name of the package where the function is located.

  4. Comment: Packages provide a on opportunity to create a data function based on a predefined statistical R or TERR function by using a downloaded package.

  5. In the Name field, type the name of the function.

  6. Comment: If you are using packages, remember that Spotfire cannot find a function unless the name is exactly the same as the one used in the package. See the documentation for the service of interest for more information about packages.

  7. When registering data functions based on predefined functions from statistical packages, in the Function name field, type the exact name of the function of interest, as it was defined in the package.

  8. Comment: This step is not applicable for script-based data functions.

  9. Optionally, provide a Description of the function to make it easier to use by others.

  10. On the Input Parameters tab, add all required input parameters.

    Comment: How the input parameters should be handled is defined upon execution of the data function.

  11. If necessary, move the input parameters so that the order in the list reflects the order in which the input parameters should be retrieved.

  12. On the Output Parameters tab, add all required output parameters.

    Comment: How the output parameters should be handled is defined upon execution of the data function.

  13. Optionally, choose an Icon that describes what your data function does.

  14. Comment: By selecting a suitable category, you can make it easier for end users to find the right data function in the library.

  15. Save the data function to the library.

    Comment: You can specify keywords upon saving that will help in locating the function in the library at a later stage. If you have chosen a different icon than the default, the icon category is automatically added as a keyword.

    Response: The registered data function is saved in the library.

  16. Click Close.

    Comment: The data function can now be added to an analysis by running it from the Files and data or the f(x) flyout, from Data Function Properties > Insert, or, by adding it as a transformation (see How to Use a Data Function for more information).

To use an alternative calculation engine:

These steps are applicable when using a custom calculation engine instead of the engine defined by the Spotfire administrator on the server.

  1. On the menu bar, select Tools > Options.

  2. Go to the Data functions page.

  3. Click Custom URL.

  4. Type or paste the address to the local calculation engine.

  5. Click OK.

To use a specific python.exe as the Python engine:

If you want to run Python-based data functions using a specific python.exe, for example, to test your script using a different version of Python you can change this in the Options dialog.

  1. On the menu bar, select Tools > Options.

  2. Go to the Data functions page.

  3. Click Use specific python.exe.

  4. Type or paste the address to the local file.

  5. Click OK.

To export a data function definition:

You can export a script/data function definition to disk if you want to share it with others or if you prefer to edit scripts in other script editing environments.

  1. Make sure you have the data function script definition you want to export open in the Register Data Functions dialog.

  2. Click Export.

  3. Browse to the location where you want to save the file and type a File name.

  4. Click Save.

To import a data function definition:

You can import a script function definition that you have previously exported to disk or have written using another script editing tool. The script file should use the extension *.sfd.

  1. In Spotfire, on the menu bar, select Tools > Register data functions.

  2. Click Import.

  3. Browse to locate the script function definition.

  4. Click Open.

Tip: If you want to add a simple calculation you can create an expression function where you add TERR scripts directly in the expression language by using the TERR_* functions available under Statistical Functions. They can then be used as any other functions in the expression language in calculated columns and custom expressions. However, note that expression functions cannot be shared between different analyses.

See also:

How to Debug a Data Function

Manage Trust

How to Use TERR Tools

How to Use Python Tools