E B E B - 16 days ago 5
R Question

CVlm {DAAG}: setting printit = FALSE causes an issue - object 'sumss' not found

I am using the

CVlm {DAAG}
and I wanted to set the
printint=FALSE
since the default says

printit if TRUE, output is printed to the screen


I tried to run the function with both
plotit
and
printit
to
FALSE
and then I found the error:
sumss
variable not found
.

Is there a way to actually set the
printit
and
plotit
to
FALSE
since I do not want the plot nor the table printed on the screen?

Answer

Relax, you have found a bug for CVlm {DAAG}. I am sure you have set both printit and plotit to FALSE, which reproduces the issue. Consider the following reproducible example:

library(DAAG)
CVlm(printit = FALSE)  ## OK, plot generated, no ANOVA table printed
CVlm(plotit = FALSE)  ## OK, ANOAV table printed, no plot generated
CVlm(printit = FALSE, plotit = FALSE)  ## Oops...
# Error in CVlm(printit = FALSE, plotit = FALSE) : object 'sumss' not found

Now, a quick scan of the source code reveals the issue. Local variable sumss is defined at:

if (printit | plotit) {
    sumss <- 0
    sumdf <- 0
    ## ...blablabla
    }

i.e., either printit and plotit needs be TRUE to declare and initialize sumss. However, in the very end of CVlm:

attr(data, "ms") <- sumss/sumdf
attr(data, "df") <- sumdf

there is no if condition to protect them. Therefore, when you reach those lines, you get "variable not found" error.

I am not package author or maintainer so I am not keen on fixing this issue. I just suggest you to keep plotit = TRUE.