fit_models has checks to validate formula, but they are are too stringent, because they don't catch formula that include functions of columns in colData.
if (length(model_form[[2]]) == 1) {
if (!as.character(model_form[[2]]) %in% c(names(colData(cds)), "~", "1", "|", "+", "-", ":", "*", "^", "I")) {
stop(paste(as.character(model_form[[2]][[i]]), "formula element is missing"))
}
} else {
for(i in 1:length(model_form[[2]])) {
if (!as.character(model_form[[2]][[i]]) %in% c(names(colData(cds)), "~", "1", "|", "+", "-", ":", "*", "^", "I")) {
stop(paste(as.character(model_form[[2]][[i]]), "formula element is missing"))
}
}
}