StatsModels.jl icon indicating copy to clipboard operation
StatsModels.jl copied to clipboard

Preserve original expression when parsing a formula in terms2.0?

Open dmbates opened this issue 6 years ago • 1 comments

As discussed in https://github.com/JuliaInterop/RCall.jl/issues/306 I think it would be helpful to preserve a copy of the original expression passed to the @formula macro, either in the FormulaTerm type or perhaps in a Formula type that contains this expression and the FormulaTerm.

My reasons for suggesting this are twofold:

  1. I have users who want to have main effects, two-factor interactions, three-factor interactions, etc. and a formula like
y ~ 1 + A * B * C * D * ...

gets expanded to

y ~ 1 + A + B + C + D + ... + A & B + A & C + ...

when I include it in the show method for the fitted model.

  1. It is easier in the RCall conversion from a Julia formula to an R formula is you can just grab hold of the original expression rather than needing to reconstruct it from the lhs and the expanded rhs.

dmbates avatar Jun 04 '19 19:06 dmbates

Indeed, it would make sense that when printing models we show the original formula that the user typed instead of the expanded one.

nalimilan avatar Jun 08 '19 14:06 nalimilan