Douglass.jl
Douglass.jl copied to clipboard
Feature request: begin/end blocks working on one dataframe
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.
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?
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.