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:
yy
instead of y
in the anonymous function provided to apply()
(to rule out some stupid naming issues regarding y
)local({...})
block and check it in R, as was suggested in why a "subscript out of bounds" error in Shiny, but not R?Version & configuration information
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.
Here's a short summary of the response I got from Spotfire support:
list()
structure properly, causing a fault in the dimensions of the matrix it was supposed to create); they're currently working on fixing itc()
instead of list()
in the data definitionModified 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")
)
)
)