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:
- use
yy
instead ofy
in the anonymous function provided toapply()
(to rule out some stupid naming issues regardingy
) - put everything in a
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
- 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.