You can use the
Expression Function dialog (reached from
Data Function Properties) to register a function in
the Spotfire expression language that is based on Spotfire® Enterprise Runtime
for R (a/k/a TERR™). Once an expression function has been created, it is
automatically available as any other function in the Spotfire expression
language, within the current analysis.
Procedure
-
On the menu bar, select
.
-
Click the
Expression Functions tab.
-
Click
New.
-
In the
Expression Function dialog, add a
Name and a
Description.
These will be shown when browsing the function list (for example
when adding a calculated column or a custom expression).
-
Select a
Function type, a
Return type and a
Category.
The Function type specifies whether the new expression function
should be a column function or an aggregation function. A
Column function returns the same number of
rows as the input, whereas an
Aggregation function aggregates the input
values into a single output value.
The
Return type specifies the Spotfire data type
that the script should return.
The
Category determines where in the
function list to place the function. A proper
categorization of the functions may make them easier to find when working with
them in expressions.
-
Define your
Script based on TERR.
For example:
# Define the CelsiusToFahrenheit function:
CelsiusToFahrenheit <- function(TempCelsius)
{
TempFahrenheit <- TempCelsius * (9/5) + 32
TempFahrenheit
}
# Run the function to produce the output
output <- CelsiusToFahrenheit(TempCelsius = input1)
For column functions the script should return the same number of
rows as the input, whereas for an aggregation function the script should
aggregate the input values into a single output value. The output must be
placed in a variable called
output.
Note: Make sure that the output from the script matches the selected
return type. For example, the script in the example will produce a Real value,
hence, Real should be selected as the return type.
-
Click
OK.
Results
The expression
function is added to the analysis.