Skip to content

Commit 5233d52

Browse files
committed
add support for : and no cols in @pivot_longer
1 parent 62ef612 commit 5233d52

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

src/parsing.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,11 @@ function parse_tidy(tidy_expr::Union{Expr,Symbol,Number}; # Can be symbol or exp
5959
var = QuoteNode(var)
6060
return :(Not($var))
6161
elseif @capture(tidy_expr, var_Symbol)
62-
return QuoteNode(var)
62+
if var == Symbol(":")
63+
return var
64+
else
65+
return QuoteNode(var)
66+
end
6367
elseif @capture(tidy_expr, var_Number)
6468
if var > 0
6569
return var

src/pivots.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ end
4141
$docstring_pivot_longer
4242
"""
4343
macro pivot_longer(df, exprs...)
44+
if length(exprs) == 0
45+
exprs = (:(:),)
46+
end
4447
exprs = parse_blocks(exprs...)
4548

4649
# take the expressions and return arg => value dictionary

test/test_pivots.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,21 @@ end
4545
value = ["A","B","A","B"],
4646
)
4747
test_long6 = @pivot_longer(test_df, -[label,num])
48+
49+
true_long7 = DataFrame(
50+
variable = ["label","label","label","label","name","name","name","name","num","num","num","num"],
51+
value = [1,1,2,2,"A","B","A","B",1,2,3,4],
52+
)
53+
test_long7 = @pivot_longer(test_df, :)
54+
test_long8 = @pivot_longer(test_df)
4855

4956
@test all(Array(true_long1 .== test_long1))
5057
@test all(Array(true_long1 .== test_long2))
5158
@test all(Array(true_long3 .== test_long3))
5259
@test all(Array(true_long3 .== test_long4))
5360
@test all(Array(true_long5 .== test_long5))
5461
@test all(Array(true_long6 .== test_long6))
62+
@test all(Array(true_long7 .== test_long7))
63+
@test all(Array(true_long7 .== test_long8))
5564
end
5665
end

0 commit comments

Comments
 (0)