handling grouping variables that aren't names (e.g. `(f|1)`)
- Dominant language
- R
- Stars
- 7
- Forks
- 3
- PR merge metrics
- No merged PRs in 30d
Description
From https://github.com/glmmTMB/glmmTMB/issues/1259:
```r
library(reformulas)
form1 <- y~diag(covariates|dummy)
form2 <- y~diag(covariates|1)
findbars_x(form1) ## us(covariates | dummy)
findbars_x(form2) ## NULL
```
the fundamental (internal) problem is that `expandGrpVar(quote(dummy))` is `list(dummy)`, while `expandGrpVar(1)` is `list()`. More fundamentally, `attr(terms(~1), "term.labels")` is empty (`character(0)`) while `attr(terms(~dummy), "term.labels")` is "dummy"
Maybe the easiest thing would be to warn if "term.labels" is empty at this point within `expandGrpVar` ?
The current implementation of `expandGrpVars` is
```r
expandGrpVar <- function(f) {
form <- as.formula(makeOp(f,quote(`~`)))
mm <- terms(form)
tl <- attr(mm,"term.labels")
## reverse order: f/g -> f + g:f (for lme4/back-compatibility)
switch_order <- function(x) paste(rev(unlist(strsplit(x, ":"))), collapse = ":")
if (inForm(f, quote(`/`))) {
## vapply adds names; remove them, and reverse order of sub-terms, for back-compatibility ...
tl <- unname(vapply(tl, switch_order, character(1)))
tl <- rev(tl)
}
res <- lapply(tl, toLang)
return(res)
}
```
Could we save trouble/fit problems like this by returning early if there are no complexities (`*`, `/`, `:` , ... ?) in `f` ?
Contributor guide
No contributing guide indexed for this repository
Research direction
Read the current expandGrpVar implementation and reproduce the findbars_x(form1/form2) examples from the issue; compare expandGrpVar(quote(dummy)) with expandGrpVar(1). Done means grouping expressions such as (f|1) are handled without losing intended terms, while existing slash-order compatibility remains intact.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- r
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100