Some packages such as fixest use the pipe to separate explanatory variables from fixed effects in formulas. How can I use update()
to modify each of those parts? In the example below, I would like to remove z
from the right-hand side but keep the fixed effects fe
.
f <- log(y) ~ log(x) + z | fe
# does not work
f |> update(~ . - z)
#> log(y) ~ (log(x) + z | fe)
f |> update(~ . - z | .)
#> log(y) ~ ((log(x) + z | fe) - z | (log(x) + z | fe))
Created on 2023-02-26 with reprex v2.0.2
Apparently, the fixest authors have only created an update()
method for model objects that supports this behavior but none for formula objects (see here). Is there any workaround other than fitting a model, updating it and then extracting the formula? In the worst case, I could manipulate the formula as a character string but that feels rather heavy-handed. rlang and modelr don't seem to have any appropriate functions either.