I am writing an R package, in which users write formulas that look like this:
outcome ~ var1 + var2 + mm(id, mmc(var3, var4), mmw(pupils^exp(teacher*b)))
The right-hand side includes variable names and the element mm(), which itself contains a variable name (id) and the elements mmc() and mmw().
I would like to separate mm(), mmc(), mmw(), i.e. end up with variables
mm = id, mmc(var3, var4), mmw(pupils^exp(teacher*b))
mmc = var3, var4
mmw = pupils^exp(teacher*b)
Is my only option to parse the formula as characters and then use regex to separate the elements or are there ways to handle this more elegantly since it is a formula?
I have tried
all.vars
all.names
but they break up mmw() too much since mmw() typically contains nonlinear functional relationships