Mistakes in plain sight

stats
R
Mixed models and power
Author

Zhenglei Gao

Published

April 29, 2025

I frequently make mistakes that are so simple and I will ask myself why I couldn’t spot it without checking for so many times or a helpful colleague pointing it out to me.

An example of one recent mistake is shown below, where I used | instead of ||.

[1] "Error in if (is.null(list(...)$direction) | list(...)$direction == \"decreasing\") { : \n  argument is of length zero\n"
attr(,"class")
[1] "try-error"
attr(,"condition")
<simpleError in if (is.null(list(...)$direction) | list(...)$direction == "decreasing") {    direction <- "decreasing"    comparisons <- paste(wt$dose, "- 0 >= 0")} else {    direction <- "increasing"    comparisons <- paste(wt$dose, "- 0 <= 0")}: argument is of length zero>

Another example is when coding shiny app modules, the name of the name space should be consistent between UI and Server components. I often got irresponsive parts where I spend long time to find out why and lots of the time it turned out to be a typo somewhere. Debugging in scripts is not always easy but at least you know there is something wrong. Error messages, even cryptic ones, alert you to the problem. In interactive applications like Shiny, the issues can be more insidious - parts simply don’t work with no error message to guide you. These “silent failures” are often the most time-consuming to track down.

-TBC-