Skip to content

Commit

Permalink
add ready examples to docstring for rselect, rtransform (JuliaData#321)
Browse files Browse the repository at this point in the history
  • Loading branch information
mahiki committed Jan 19, 2022
1 parent 41a6e29 commit 13d06a7
Showing 1 changed file with 52 additions and 2 deletions.
54 changes: 52 additions & 2 deletions src/macros.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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...))
Expand Down Expand Up @@ -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...))
Expand Down

0 comments on commit 13d06a7

Please sign in to comment.