Products | Versions |
---|---|
Spotfire Statistics Services | All supported versions |
This will be seen when execution of a data function's script leads to more than 65535 characters of warning messages. This is beyond the maximum character count allowed for the WARNINGS column in the TIBCO Spotfire Statistics Services server application database, which stores the job execution history. The job execution fails because TIBCO Spotfire Statistics Services does not currently truncate warnings.
You can avoid this issue by rewriting the data function's script to reduce the number (and length) of warnings generated in its execution.
It is also possible to suppress the return of warnings generated in the script. Available options for doing this include the following:
Option 1:
Wrap the entire problematic script in a call to the function provided below, suppressTrailingWarnings(), which will suppress all but the first 'nWarningsToSignal' warnings.
suppressTrailingWarnings <- function(expr, nWarningsToSignal = 5)
{
nWarnings <- 0
on.exit(
if (nWarnings >= nWarningsToSignal) {
warning("Only the first ", nWarningsToSignal - 1, " of ", nWarnings, " warnings were reported")
}
)
withCallingHandlers(
expr,
warning=function(w){
nWarnings <<- nWarnings + 1
if (nWarnings < nWarningsToSignal) {
warning(w)
}
invokeRestart("muffleWarning")
}
)
}
Since this function is not defined in a package, you need to define it in the data function script.
For example, assume your failing script is:
fit <- lm(Y ~ X1 + X2, data = DATA)
RESIDUALS <- residuals(fit)
FITTEDVALUES <- fitted(fit)
Define the suppressTrailingWarnings() function and then wrap the problematic function in it, like this:
suppressTrailingWarnings <- function(expr, nWarningsToSignal = 5)
{
nWarnings <- 0
on.exit(
if (nWarnings >= nWarningsToSignal) {
warning("Only the first ", nWarningsToSignal - 1, " of ", nWarnings, " warnings were reported")
}
)
withCallingHandlers(
expr,
warning=function(w){
nWarnings <<- nWarnings + 1
if (nWarnings < nWarningsToSignal) {
warning(w)
}
invokeRestart("muffleWarning")
}
)
}
suppressTrailingWarnings({
fit <- lm(Y ~ X1 + X2, data = DATA)
RESIDUALS <- residuals(fit)
FITTEDVALUES <- fitted(fit)
}, nWarningsToSignal = 3) # default is 5
That function should emit at most 'nWarningsToSignal' warnings (including a possible trailing warning that says how many were not reported). For example:
> funkyFunction <- function(i) if (i<0) warning(i, " is negative")
>
> suppressTrailingWarnings(for(i in 5:-3) funkyFunction(i))
Warning messages:
1: In funkyFunction(i) : -1 is negative
2: In funkyFunction(i) : -2 is negative
3: In funkyFunction(i) : -3 is negative
>
> suppressTrailingWarnings(for(i in 5:-300) funkyFunction(i))
Warning messages:
1: In funkyFunction(i) : -1 is negative
2: In funkyFunction(i) : -2 is negative
3: In funkyFunction(i) : -3 is negative
4: In funkyFunction(i) : -4 is negative
5: In suppressTrailingWarnings(for(i in 5:-300) funkyFunction(i)) : Only the first 4 of 300 warnings were reported
Option 2:
For single statements, you can use the suppressWarnings() function, but this is inefficient for more complex data functions:
suppressWarnings( expr )
Option 3:
You can disable warnings globally with the options() function, but it is not optimal to completely disable warnings:
options( warn = -1 )
Disclaimer:
The code in this article is only a sample to be used as a reference. It is not intended to be used "As Is" in a Production environment. Always test in a Development environment. Make modifications to the code in accordance with your implementation specifications that best suit your business requirements. Refer to the reference(s) cited in this article for usage of the functions and methods used in the code.