From 13d06a74fe69f9d4ffd722adbd14ca090a2f138a Mon Sep 17 00:00:00 2001 From: mahiki Date: Tue, 18 Jan 2022 22:21:17 -0800 Subject: [PATCH] add ready examples to docstring for rselect, rtransform (#321) --- src/macros.jl | 54 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 2 deletions(-) diff --git a/src/macros.jl b/src/macros.jl index 9d8712be..bbe744c5 100644 --- a/src/macros.jl +++ b/src/macros.jl @@ -1403,8 +1403,33 @@ end """ @rtransform(x, args...) -Row-wise version of `@transform`, i.e. all operations use `@byrow` by -default. See [`@transform`](@ref) for details. +Row-wise version of `@transform`, i.e. all operations use `@byrow` by default. +See [`@transform`](@ref) for details. + +### Examples +```jldoctest +julia> df = DataFrame(x = 1:5, y = 11:15) +5×2 DataFrame + Row │ x y + │ Int64 Int64 +─────┼────────────── + 1 │ 1 11 + 2 │ 2 12 + 3 │ 3 13 + 4 │ 4 14 + 5 │ 5 15 + +julia> @rtransform(df, :a = :x + :y ^ 2, :c = :y == 13 ? 999 : 1 - :y) +5×4 DataFrame + Row │ x y a c + │ Int64 Int64 Int64 Int64 +─────┼──────────────────────────── + 1 │ 1 11 122 -10 + 2 │ 2 12 146 -11 + 3 │ 3 13 172 999 + 4 │ 4 14 200 -13 + 5 │ 5 15 230 -14 +``` """ macro rtransform(x, args...) esc(rtransform_helper(x, args...)) @@ -1659,6 +1684,31 @@ end Row-wise version of `@select`, i.e. all operations use `@byrow` by default. See [`@select`](@ref) for details. + +### Examples +```jldoctest +julia> df = DataFrame(x = 1:5, y = 10:14) +5×2 DataFrame + Row │ x y + │ Int64 Int64 +─────┼────────────── + 1 │ 1 10 + 2 │ 2 11 + 3 │ 3 12 + 4 │ 4 13 + 5 │ 5 14 + +julia> @rselect(df, :x, :A = mod(:y, :x) == 0 ? 99 : :x) +5×2 DataFrame + Row │ x A + │ Int64 Int64 +─────┼────────────── + 1 │ 1 99 + 2 │ 2 2 + 3 │ 3 99 + 4 │ 4 4 + 5 │ 5 5 +``` """ macro rselect(x, args...) esc(rselect_helper(x, args...))