Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for everything() and docstrings for helper functions. #48

Merged
merged 2 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# TidierData.jl updates

## v0.12.2 - 2023-09-20
- Adds support for `everything()` selection helper.
- Adds docstrings for `everything()`, `starts_with()`, `ends_with()`, and `matches()`

## v0.12.1 - 2023-09-11
- Fixes bug in `@separate()` so that the value of `into` supports interpolation.

Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "TidierData"
uuid = "fe2206b3-d496-4ee9-a338-6a095c4ece80"
authors = ["Karandeep Singh"]
version = "0.12.1"
version = "0.12.2"

[deps]
Chain = "8be319e6-bccf-4806-a6f7-6fae938471bc"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ TidierData.jl also supports the following helper functions:
- `n()` and `row_number()`
- `ntile()`
- `lag()` and `lead()`
- `starts_with()`, `ends_with()`, `matches()`, and `contains()`
- `everything()`, `starts_with()`, `ends_with()`, `matches()`, and `contains()`
- `as_float()`, `as_integer()`, and `as_string()`
- `is_float()`, `is_integer()`, and `is_string()`

Expand Down
2 changes: 1 addition & 1 deletion docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ TidierData.jl also supports the following helper functions:
- `n()` and `row_number()`
- `ntile()`
- `lag()` and `lead()`
- `starts_with()`, `ends_with()`, `matches()`, and `contains()`
- `everything()`, `starts_with()`, `ends_with()`, `matches()`, and `contains()`
- `as_float()`, `as_integer()`, and `as_string()`
- `is_float()`, `is_integer()`, and `is_string()`
```
Expand Down
2 changes: 1 addition & 1 deletion src/TidierData.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ using Reexport
@reexport using Statistics
@reexport using ShiftedArrays: lag, lead

export TidierData_set, across, desc, n, row_number, starts_with, ends_with, matches, if_else, case_when, ntile,
export TidierData_set, across, desc, n, row_number, everything, starts_with, ends_with, matches, if_else, case_when, ntile,
as_float, as_integer, as_string, is_float, is_integer, is_string, @select, @transmute, @rename, @mutate, @summarize, @summarise, @filter,
@group_by, @ungroup, @slice, @arrange, @distinct, @pull, @left_join, @right_join, @inner_join, @full_join,
@pivot_wider, @pivot_longer, @bind_rows, @bind_cols, @clean_names, @count, @tally, @drop_missing, @glimpse, @separate,
Expand Down
144 changes: 142 additions & 2 deletions src/docstrings.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2230,7 +2230,7 @@ const docstring_slice_sample =
"""
@slice_sample(df, [n = 1, prop, replace = false])

Randomly sample rows from a DataFrame `df` or from each group in a GroupedDataFrame. The default is to return 1 row. Either the number of rows (`n`) or the proportion of rows (`prop`) should be provided as a keyword argument
Randomly sample rows from a DataFrame `df` or from each group in a GroupedDataFrame. The default is to return 1 row. Either the number of rows (`n`) or the proportion of rows (`prop`) should be provided as a keyword argument.

# Arguments
- `df`: The source data frame or grouped data frame from which to sample rows.
Expand Down Expand Up @@ -2300,4 +2300,144 @@ julia> @chain df begin
4 │ 9 19
5 │ 8 18
```
"""
"""

const docstring_starts_with =
"""
starts_with(prefix)

Select all columns starting with the `prefix`.

# Arguments
- `prefix`: A string.

# Examples
```julia
julia> df = DataFrame(a_1 = 1:5, a_2 = 11:15, b_1 = 21:25);

julia> @chain df begin
@select(starts_with("a"))
end
5×2 DataFrame
Row │ a_1 a_2
│ Int64 Int64
─────┼──────────────
1 │ 1 11
2 │ 2 12
3 │ 3 13
4 │ 4 14
5 │ 5 15
```
"""

const docstring_ends_with =
"""
ends_with(suffix)

Select all columns ending with the `suffix`.

# Arguments
- `suffix`: A string.

# Examples
```julia
julia> df = DataFrame(a_1 = 1:5, a_2 = 11:15, b_1 = 21:25);

julia> @chain df begin
@select(ends_with("1"))
end
5×2 DataFrame
Row │ a_1 b_1
│ Int64 Int64
─────┼──────────────
1 │ 1 21
2 │ 2 22
3 │ 3 23
4 │ 4 24
5 │ 5 25
```
"""

const docstring_matches =
"""
matches(pattern, [flags])

Select all columns matching the `pattern`.

# Arguments
- `pattern`: A string.
- `flags`: Optional string containing flags. "i" = Do case-insensitive pattern matching. "m" = Treat string as multiple lines. "s" = Treat string as a single line. "x" = Tells the regular expression parser to ignore most whitespace that is neither backslashed nor within a character class. You
can use this to break up your regular expression into (slightly) more readable parts.

# Examples
```julia
julia> df = DataFrame(a_1 = 1:5, a_2 = 11:15, b_1 = 21:25);

julia> @chain df begin
@select(matches("^a"))
end
5×2 DataFrame
Row │ a_1 a_2
│ Int64 Int64
─────┼──────────────
1 │ 1 11
2 │ 2 12
3 │ 3 13
4 │ 4 14
5 │ 5 15

julia> @chain df begin
@select(matches("1\$"))
end
5×2 DataFrame
Row │ a_1 b_1
│ Int64 Int64
─────┼──────────────
1 │ 1 21
2 │ 2 22
3 │ 3 23
4 │ 4 24
5 │ 5 25

julia> @chain df begin
@select(matches("A", "i"))
end
5×2 DataFrame
Row │ a_1 a_2
│ Int64 Int64
─────┼──────────────
1 │ 1 11
2 │ 2 12
3 │ 3 13
4 │ 4 14
5 │ 5 15
```
"""

const docstring_everything =
"""
everything()

Select all (remaining) columns.

# Arguments
- None

# Examples
```julia
julia> df = DataFrame(a_1 = 1:5, a_2 = 11:15, b_1 = 21:25);

julia> @chain df begin
@select(b_1, everything())
end
5×3 DataFrame
Row │ b_1 a_1 a_2
│ Int64 Int64 Int64
─────┼─────────────────────
1 │ 21 1 11
2 │ 22 2 12
3 │ 23 3 13
4 │ 24 4 14
5 │ 25 5 15
```
"""
21 changes: 18 additions & 3 deletions src/helperfunctions.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
# This file is intended for any catch-all helper functions that don't deserve
# their own documentation page and don't have any outside licenses.

# Need to expand with docs
# These are just aliases
# These are aliases for existing Julia functions
"""
$docstring_starts_with
"""
starts_with(args...) = startswith(args...)

"""
$docstring_ends_with
"""
ends_with(args...) = endswith(args...)
matches(pattern, flags...) = Regex(pattern, flags...)

"""
$docstring_matches
"""
matches(pattern, flags...) = Regex(pattern, flags...)

"""
$docstring_everything
"""
everything() = All()