awh

License

MIT + file LICENSE

Citation

Citing this package

Authors

  • Alejandro Hagan (author, maintainer)

awh

Alejandro’s Workflow Helpers - A collection of utility functions for data analysis workflows.

Installation

# Install from Codeberg
pak::pak("codeberg::usrbinr/awh")

Functions

count_plus

An enhanced version of dplyr::count() that adds proportion and cumulative proportion columns. Works seamlessly with both tibbles and lazy tables (dbplyr).

library(awh)

# Basic usage
ggplot2::diamonds |> count_plus(color)
#> # A tibble: 7 x 5
#>   row_id color     n prop_n cumsum_prop_n
#>    <int> <ord> <int>  <dbl>         <dbl>
#> 1      1 G     11292  0.209         0.209
#> 2      2 E      9797  0.182         0.391
#> ...

# With weighted counts
ggplot2::diamonds |> count_plus(cut, .wt = price)

# Ascending order
ggplot2::diamonds |> count_plus(clarity, .sort = -1)

# Works with database connections
con |> tbl("my_table") |> count_plus(category)

validate_colnames

Validates that required columns exist in a data frame.

df <- data.frame(time = Sys.time(), temp = 72)
validate_colnames(df, c("time", "temp"))
#> TRUE

validate_colnames(df, c("time", "humidity"))
#> Error: Can not find "humidity" column in the dataset

validate_input_characters

Validates character inputs against a set of allowed values.

validate_input_characters("fcst", c("act", "fcst"))
# Passes silently

validate_input_characters("invalid", c("act", "fcst"))
#> Error: invalid is an invalid input

License

MIT