diff --git a/NEWS.md b/NEWS.md index 650b31b..2d75c93 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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. diff --git a/Project.toml b/Project.toml index ad78fe2..e3d197e 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.1" +version = "0.12.2" [deps] Chain = "8be319e6-bccf-4806-a6f7-6fae938471bc" diff --git a/README.md b/README.md index aa8b1f4..bf97f23 100644 --- a/README.md +++ b/README.md @@ -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()` diff --git a/docs/src/index.md b/docs/src/index.md index 0fe330c..ceaddf7 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -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()` ``` diff --git a/src/TidierData.jl b/src/TidierData.jl index e6a0f14..6fc2c3b 100644 --- a/src/TidierData.jl +++ b/src/TidierData.jl @@ -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, diff --git a/src/docstrings.jl b/src/docstrings.jl index 2fbd111..6afa139 100644 --- a/src/docstrings.jl +++ b/src/docstrings.jl @@ -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. @@ -2300,4 +2300,144 @@ julia> @chain df begin 4 │ 9 19 5 │ 8 18 ``` -""" \ No newline at end of file +""" + +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 +``` +""" diff --git a/src/helperfunctions.jl b/src/helperfunctions.jl index f2c4712..5bf8de8 100644 --- a/src/helperfunctions.jl +++ b/src/helperfunctions.jl @@ -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...) \ No newline at end of file + +""" +$docstring_matches +""" +matches(pattern, flags...) = Regex(pattern, flags...) + +""" +$docstring_everything +""" +everything() = All() \ No newline at end of file