|
1 | 1 | # Not exported
|
2 |
| -function parse_tidy(tidy_expr::Union{Expr,Symbol,Number}; # Can be symbol or expression |
| 2 | +function parse_tidy(tidy_expr::Union{Expr,Symbol,Number, QuoteNode}; # Can be symbol or expression |
3 | 3 | autovec::Bool=true, subset::Bool=false, from_across::Bool=false,
|
4 | 4 | from_slice::Bool = false)
|
5 | 5 | if @capture(tidy_expr, across(vars_, funcs_))
|
@@ -32,10 +32,6 @@ function parse_tidy(tidy_expr::Union{Expr,Symbol,Number}; # Can be symbol or exp
|
32 | 32 | endindex = QuoteNode(endindex)
|
33 | 33 | end
|
34 | 34 | return :(Between($startindex, $endindex))
|
35 |
| - elseif @capture(tidy_expr, names_vect) |
36 |
| - return Symbol.(names.args) |
37 |
| - elseif @capture(tidy_expr, -names_vect) |
38 |
| - return Not(Symbol.(names.args)) |
39 | 35 | elseif @capture(tidy_expr, (lhs_ = fn_(args__)) | (lhs_ = fn_.(args__)))
|
40 | 36 | if length(args) == 0
|
41 | 37 | lhs = QuoteNode(lhs)
|
@@ -75,13 +71,28 @@ function parse_tidy(tidy_expr::Union{Expr,Symbol,Number}; # Can be symbol or exp
|
75 | 71 | end
|
76 | 72 | elseif @capture(tidy_expr, !var_Number)
|
77 | 73 | return :(Not($var))
|
| 74 | + elseif @capture(tidy_expr, (tuple__,)) |
| 75 | + tuple = parse_tidy.(tuple) |
| 76 | + return :(Cols($(tuple...))) |
| 77 | + elseif @capture(tidy_expr, [vec__]) |
| 78 | + vec = parse_tidy.(vec) |
| 79 | + return :(Cols($(vec...))) |
| 80 | + elseif @capture(tidy_expr, -[vec__]) |
| 81 | + vec = parse_tidy.(vec) |
| 82 | + return :(Not(Cols($(vec...)))) # can simpify to Not($(tuple...)) in DataFrames 1.6+ |
| 83 | + elseif @capture(tidy_expr, ![vec__]) |
| 84 | + vec = parse_tidy.(vec) |
| 85 | + return :(Not(Cols($(vec...)))) # can simpify to Not($(tuple...)) in DataFrames 1.6+ |
78 | 86 | elseif !subset & @capture(tidy_expr, -fn_(args__)) # negated selection helpers
|
79 | 87 | return :(Cols(!($(esc(fn))($(args...))))) # change the `-` to a `!` and return
|
80 | 88 | elseif !subset & @capture(tidy_expr, fn_(args__)) # selection helpers
|
81 | 89 | if from_across || fn == :Cols # fn == :Cols is to deal with interpolated columns
|
82 | 90 | return tidy_expr
|
83 | 91 | elseif fn == :where
|
84 | 92 | return :(Cols(all.(broadcast($(esc(args...)), eachcol(DataFrame(df_copy))))))
|
| 93 | + elseif fn == :- || fn == :! # for negated selection as in -(A, B), which is internally represnted as function |
| 94 | + args = parse_tidy.(args) |
| 95 | + return :(Not(Cols($(args...)))) # can simpify to Not($(tuple...)) in DataFrames 1.6+ |
85 | 96 | else
|
86 | 97 | return :(Cols($(esc(tidy_expr))))
|
87 | 98 | end
|
|
0 commit comments