Question

When I try running the following piece of code in Spotfire Professional as a "R Script - Tibco Enterprise Runtime for R":

mydata_broken <- structure(
  list(
    Var1 = list(3.99083333270391, 3.99083333270391, 3.99083333270391, 3.99083333270391), 
    Var2 = list(3.99083333270391, 3.99083333270391, 3.99083333270391, 3.99083333270391)), 
  row.names = c("1", "2", "3", "4"), 
  class = "data.frame", 
  out.attrs = list(dim = c(2L, 2L), 
                   dimnames = list(
                     Var1 = c("Var1=3.99083333270391", "Var1=3.99083333270391"), 
                     Var2 = c("Var2=3.99083333270391", "Var2=3.99083333270391")
                     )
                   )
  )

mydata_ok <- structure(
  list(
    Var1 = list(3.99083333270391), 
    Var2 = list(3.99083333270391)), 
  row.names = "1", 
  class = "data.frame", 
  out.attrs = list(dim = c(1L, 1L), 
                   dimnames = list(
                     Var1 = "Var1=3.99083333270391", 
                     Var2 = "Var2=3.99083333270391")
                   )
  )

out <- apply(mydata_broken, 1, function(y) mean(as.numeric(y)))

I get the following error message:

TIBCO Enterprise Runtime for R returned an error: 'Error in expand.names(x) : subscript out of bounds'. at Spotfire.Dxp.Data.DataFunctions.Executors.LocalFunctionClient.OnExecuting(FunctionClient funcClient)

(rest of stack trace omitted)

However, the same code works flawlessly in plain R. If I replace mydata_broken with mydata_ok in the call to apply(), everything works as expected (both in TERR and plain R).

Things I've tried so far:

Version & configuration information

  • Spotfire 5.5.0, build version 5.5.0.31, build date: 22.05.2013
  • R version 3.0.2, 64bit (2013-09-25)
  • Windows 7, 64bit

So, my question is: Am I making some stupid mistake here? Or is this a bug in the Spotfire R runtime?

UPDATE I'd like to reopen the question, because I got a viable workaround from Spotfire support, and I'd like to add it as an answer.

Was it helpful?

Solution

Here's a short summary of the response I got from Spotfire support:

  • it's indeed a bug in TERR (apparently, TERR is not able to read the list() structure properly, causing a fault in the dimensions of the matrix it was supposed to create); they're currently working on fixing it
  • as a workaround, you can use c() instead of list() in the data definition

Modified definition of data that works in TERR

mydata_working <- structure(
    list(
      Var1 = c(3.99083333270391, 3.99083333270391, 3.99083333270391, 3.99083333270391), 
      Var2 = c(3.99083333270391, 3.99083333270391, 3.99083333270391, 3.99083333270391)), 
    row.names = c("1", "2", "3", "4"), 
    class = "data.frame", 
    out.attrs = list(dim = c(2L, 2L), 
                     dimnames = list(
                       Var1 = c("Var1=3.99083333270391", "Var1=3.99083333270391"), 
                       Var2 = c("Var2=3.99083333270391", "Var2=3.99083333270391")
                       )
                     )
    )
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top