Clarify error message when factor is required
enhancement
**Summary**
The error below is due to the fact that the `TRTA` column must be a factor and not a character vector.
I think that it would be preferable if either:
1. The error message were clarified to tell which column in the input is leading to the error (i.e. tell that `TRTA` needs to be a factor rather than `coordinates[[1L]]`)
2. If acceptable, character inputs were automatically converted to factors. (Though, I understand that this may not be preferred since factor ordering is often important.)
** Reprex **
``` r
library(mmrm)
library(tidyverse)
d <-
data.frame(
USUBJID = factor(rep(1:6, each = 2)),
TRTA = rep(c("A", "B"), 6)
) |>
mutate(
lnAVAL =
log(case_when(
TRTA == "A" ~ 100,
TRTA == "B" ~ 120
)*exp(rnorm(n = n(), mean = 0, sd = 0.1)))
)
mmrm(
formula = lnAVAL ~ TRTA + us(TRTA|USUBJID),
data = d
)
#> Error in h_mmrm_tmb_data(formula_parts, data, weights, reml, singular = if (control$accept_singular) "drop" else "error", : Assertion on 'coordinates[[1L]]' failed: Must be of type 'factor', not 'character'.
```
<sup>Created on 2025-11-20 with [reprex v2.1.1](https://reprex.tidyverse.org)</sup>
0 条评论