Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save datalove/76d52a561402e9a9c213 to your computer and use it in GitHub Desktop.
Save datalove/76d52a561402e9a9c213 to your computer and use it in GitHub Desktop.
TERR Script to be used in a Spotfire 'Expression Function'0
#######################################################
#
# Expression Functions in Spotfire can take arbitrarily
# many columns as input. Columns will be passed to TERR
# in order as 'input1', 'input2', etc.
#
# This shows how to capture an arbitrary number of
# columns and to put them into a data frame.
#
#######################################################
inputs <- grep("^input[0-9]+$",ls(), value = TRUE)
# capture columns as a matrix
my.matrix <- sapply(inputs, function(x) {eval(parse(text = x))})
# capture columns as a data frame
my.df <- as.data.frame(sapply(inputs, function(x) {eval(parse(text = x))}))
# Now do something with the matrix or dataframe that evaluates
# to a vector of length equal to the number of rows in the table
# i.e. length(input1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment