In R, the formula object is symbolic, and it is quite difficult to parse. However, I need to parse such a formula into an explicit set of labels for use outside of R.
(1)
The provision f represents model formulas in which the answer is not specified, for example. ~V1 + V2 + V3 , I tried:
t <- terms(f) attr(t, "term.labels")
However, this does not give what is explicitly obvious if some of the variables in f are categorical. For example, let V1 be a categorical variable with two categories, i.e. Logical, and V2 is double.
Therefore, the model specified by ~V1:V2 must have 2 parameters: "interception" and "xyes: z". Meanwhile, the model specified by ~V1:V2 - 1 should have the parameters "xno: z" and "xyes: z". However, without specifying the terms() function, which variables are categorical (and how many categories), it is not possible to interpret them. Instead, it simply has V1:V2 in its "terms.labels", which means nothing in the context that V1 is categorical.
(2)
Using model.matrix , on the other hand, is an easy way to get exactly what I want. The problem is that this requires the data argument, which is bad for me, because I only need to explicitly interpret the symbolic formula to use outside R. This way of getting this will be time-consuming (comparative), since R has to read data from external source, when all he really needs to know for the formula is variables that are categorical (and how many categories) and which variables double.
Is it possible to use "model.matrix" only with data types and not actual data? If not, what else is a viable solution?