Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

An alternative syntax for formulas? #3

Closed
ararslan opened this issue Oct 15, 2016 · 2 comments
Closed

An alternative syntax for formulas? #3

ararslan opened this issue Oct 15, 2016 · 2 comments
Assignees

Comments

@ararslan
Copy link
Member

ararslan commented Oct 15, 2016

What we have

Currently formulas are constructed using @~, which as far as I know is Julia's only infix macro. This allows us to mirror R's formulas, which take advantage of R's nonstandard evaluation, and avoid prefixing variable names with :.

However, this is a special case that Julia makes in parsing that it—at least in my opinion—shouldn't have to do to allow Julia to look like R in one scenario. It would be nice if Julia could avoid having to parse anything as an infix macro. Plus, there surely is a more Julian approach!

A solution

A while back, @dmbates suggested on the mailing list that we replace our current formula syntax with Pairs. Based on my understanding, this would look like :y => :(1 + x1 + x2). @StefanKarpinski alternatively suggested the use of a @model macro, which would take an expression and construct a formula or model object, which could then be passed to fit or what have you. I imagine this looking something like

fit(LinearRegressionModel, @model y ~ 1 + x1 + x2, ...)

This approach allows any separator for the dependent and independent variables, not just ~, since it simply becomes the head in the resulting Expr. We could even use = for a more SAS-like aesthetic, or => as in Pairs.

A call to action

As we're transitioning the modeling functionality out of DataFrames.jl and into its own package (this one!), we have the opportunity to revisit some design decisions such as this. What do you all think? Should we leave things as-is or blaze a new trail?

@kleinschmidt
Copy link
Member

kleinschmidt commented Oct 15, 2016

I like the @model macro: it makes it very clear what the intent of the formula is (to represent a model), thus potentially heading off some of the "punning" on ~ in R as a generic quotation operator.

Unless I'm misunderstanding something, we'd still need some kind of macro to use pairs. Or require that people make sure that both sides are quoted, like :y => :(1+x), which feels clunky to me, and more importantly potentially confusing to users ("why do I need a :y on the left but x on the right??")

@nalimilan
Copy link
Member

See also previous discussion at https://groups.google.com/d/msg/julia-stats/LdozV7o4zuM/469sTB2HEQAJ.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants