Spotfire® Enterprise Runtime for R

TERR_TimeSpan

In the Spotfire Custom Expressions dialog box, you can select the pre-defined expression TERR_TimeSpan from the Function list. This expression function invokes the TERR engine to return a vector or a single column data frame of the data type difftime , which is converted to a Spotfire column of the corresponding Spotfire data type TimeSpan.

The expression function has at least two arguments.
Argument Argument description
A TERR script. The TERR script contains the following.
  • A number of variables using the naming convention that Spotfire requires: input1 to inputN, where inputN is the highest number of the specified inputs, numbered sequentally.
  • A TERR assignment operator (<-) that assigns the results of the TERR evaluation to an object named output (also using the naming convention that Spotfire requires).
Spotfire column names. Passed as additional arguments, these are the data column names that input1 to inputN represent. All columns must be the same length.
The output type is returned from TERR and converted by Spotfire.
Returned by TERR Converted in Spotfire
A vector or a single column data frame of data type difftime. A column with the same number of rows as the input, and of the data type TimeSpan.

TERR_TimeSpan example

In this example, in Spotfire, take thirty observations with a start time and an end time. You can find the sample data set in Observation data set for Spotfire examples.
Tip: You can copy (CTRL+C) the contents of the sample data table and paste it (CTRL+V) into the Spotfire user interface.
Calculate the observation time for each entry.
TERR_TimeSpan("output <- difftime(input1, input2)",[End time],[Start time])

In the example, we named the resulting column Elapsed time and added the column to a table visualization. The resulting table in Spotfire shows the following.


TERR_TimeSpan

Important: Spotfire autocorrects the function case or name to that of built-in Spotfire function names. (For example, TERR contains the function max, and Spotfire contains the function Max. ) You must overwrite this autocorrection manually to ensure that you use the TERR function case and name in your expression function.

See Embedding the Contents of a Script in an Expression Function for a detailed procedure for creating an expression function.