From 52d3132d3ef69bd2f3785ada77b9f35ea0f6bf49 Mon Sep 17 00:00:00 2001 From: drizk1 Date: Fri, 1 Sep 2023 08:15:13 -0400 Subject: [PATCH 1/3] added interpolation support to separate --- docs/examples/UserGuide/sep_unite.jl | 6 ++++++ src/separate_unite.jl | 25 ++++++++++++++++--------- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/docs/examples/UserGuide/sep_unite.jl b/docs/examples/UserGuide/sep_unite.jl index be6e6da5..c2acd9d9 100644 --- a/docs/examples/UserGuide/sep_unite.jl +++ b/docs/examples/UserGuide/sep_unite.jl @@ -10,6 +10,12 @@ df = DataFrame(a = ["1-1", "2-2", "3-3-3"]); @separate(a, (b, c, d), "-") end +# The into columns can also be designated as follows + +new_names = ["x$(i)" for i in 1:3]; ### or new_names = ["b", "c", "d"], or new_names = [:b, :c, :d] + +@separate(df, a, new_names, "-") + # The `@unite` macro brings together multiple columns into one, separate the characters by a user specified delimiter # ## Here, the `@unite` macro combines the "b", "c", and "d" columns columns into a single new "new_col" column using the "/" delimiter diff --git a/src/separate_unite.jl b/src/separate_unite.jl index bd08d3fd..0695760a 100644 --- a/src/separate_unite.jl +++ b/src/separate_unite.jl @@ -28,16 +28,23 @@ end $docstring_separate """ macro separate(df, from, into, sep) - from = QuoteNode(from) - - if @capture(into, (args__,)) - elseif @capture(into, [args__]) + from_quoted = QuoteNode(from) + + if @capture(into, (args__,)) || @capture(into, [args__]) + args = QuoteNode.(args) + into_expr = :[$(args...)] + else + into_expr = quote + if typeof($into) <: Vector{String} + Symbol.($into) + else + $into + end + end end - - args = QuoteNode.(args) - - var_expr = quote - separate($(esc(df)), $from, [$(args...)], $sep) + + return quote + separate($(esc(df)), $(from_quoted), $(into_expr), $(esc(sep))) end end From 4d551b6640ef975c7c1415b55040609851e1c1f0 Mon Sep 17 00:00:00 2001 From: drizk1 Date: Fri, 1 Sep 2023 13:28:41 -0400 Subject: [PATCH 2/3] switched to use parse_i --- src/separate_unite.jl | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/separate_unite.jl b/src/separate_unite.jl index 0695760a..22817003 100644 --- a/src/separate_unite.jl +++ b/src/separate_unite.jl @@ -30,15 +30,17 @@ $docstring_separate macro separate(df, from, into, sep) from_quoted = QuoteNode(from) - if @capture(into, (args__,)) || @capture(into, [args__]) + interpolated_into, _, _ = parse_interpolation(into) + + if @capture(interpolated_into, (args__,)) || @capture(interpolated_into, [args__]) args = QuoteNode.(args) into_expr = :[$(args...)] else into_expr = quote - if typeof($into) <: Vector{String} - Symbol.($into) + if typeof($interpolated_into) <: Vector{String} + Symbol.($interpolated_into) else - $into + $interpolated_into end end end From 2f55ddcaedbfeda2449723f1bc0bb2b91d6f0ec3 Mon Sep 17 00:00:00 2001 From: Karandeep Singh Date: Mon, 11 Sep 2023 15:09:33 -0400 Subject: [PATCH 3/3] Bumped version to 0.12.1, fixed documentation due to failing test. --- NEWS.md | 3 +++ Project.toml | 2 +- docs/examples/UserGuide/sep_unite.jl | 4 ++-- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/NEWS.md b/NEWS.md index 31e26729..650b31bf 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,8 @@ # TidierData.jl updates +## v0.12.1 - 2023-09-11 +- Fixes bug in `@separate()` so that the value of `into` supports interpolation. + ## v0.12.0 - 2023-09-10 - Fixes `!!` interpolation so that it works using normal Julia scoping rules. It no longer uses `Main.eval()` in the implementation. The way interpolation works contains some breaking changes, and the documentation has been updated accordingly. - Fixes name conflict with `Cleaner.rename()` and `DataFrames.rename()` diff --git a/Project.toml b/Project.toml index 3d052d13..ad78fe2f 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "TidierData" uuid = "fe2206b3-d496-4ee9-a338-6a095c4ece80" authors = ["Karandeep Singh"] -version = "0.12.0" +version = "0.12.1" [deps] Chain = "8be319e6-bccf-4806-a6f7-6fae938471bc" diff --git a/docs/examples/UserGuide/sep_unite.jl b/docs/examples/UserGuide/sep_unite.jl index c2acd9d9..9c0888d7 100644 --- a/docs/examples/UserGuide/sep_unite.jl +++ b/docs/examples/UserGuide/sep_unite.jl @@ -12,9 +12,9 @@ end # The into columns can also be designated as follows -new_names = ["x$(i)" for i in 1:3]; ### or new_names = ["b", "c", "d"], or new_names = [:b, :c, :d] +new_names = ["x$(i)" for i in 1:3]; # or new_names = ["b", "c", "d"], or new_names = [:b, :c, :d] -@separate(df, a, new_names, "-") +@separate(df, a, !!new_names, "-") # The `@unite` macro brings together multiple columns into one, separate the characters by a user specified delimiter