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

Feature request: begin/end blocks working on one dataframe

Open korenmiklos opened this issue 3 years ago • 2 comments

Stata syntax:

frame df {
  gen z = SepalLength + SepalWidth
  replace z = _n if _n <= 10
  drop z
  bysort Species : egen z = sum(SepalLength) if SepalWidth > 3.0
}

Intended Julia syntax

@douglas df begin
  gen :z = :SepalLength .+ :SepalWidth
  replace :z = _n if _n <= 10
  drop :z
  bysort :Species : egen :z = sum(:SepalLength) if :SepalWidth .> 3.0
end

Not sure if this is doable as replace etc keywords are neither function call nor macro call.

korenmiklos avatar Jan 20 '22 21:01 korenmiklos

I guess it could be made to work, but it's not ideal. Julia automatically parses stuff inside the begin/end block into an Expr, and one would have to reconstruct the string inside the begin/end. What would, however, work, is something like

@douglass df """
  gen :z = :SepalLength .+ :SepalWidth
  replace :z = _n if _n <= 10
  drop :z
  bysort :Species : egen :z = sum(:SepalLength) if :SepalWidth .> 3.0
"""

Would this be a good substitute to what you had in mind?

jmboehm avatar Jan 21 '22 14:01 jmboehm

Because each Stata command begins with a reserved word, these could all be implemented as macros, like @replace, @egen, @merge etc. Like https://juliadata.github.io/DataFramesMeta.jl/stable/

Depends on design choices. Let's discuss on Thursday.

korenmiklos avatar Jan 21 '22 20:01 korenmiklos