Skip to content

Commit

Permalink
examples
Browse files Browse the repository at this point in the history
ref #146
  • Loading branch information
wibeasley committed Oct 28, 2023
1 parent 628fbe7 commit 60562c8
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 6 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Suggests:
RODBC,
spelling,
testthat,
tidyr,
tinytex
Encoding: UTF-8
Language: en-US
Expand Down
39 changes: 34 additions & 5 deletions R/row.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,28 +28,57 @@
#' the new column will be an [integer].
#' Otherwise the new column will be a [double].
#'
#' @note
#' @author Will Beasley
#' @importFrom rlang :=
#' @examples
#' library(OuhscMunge) #Load the package into the current R session.

#' mtcars |>
#' row_sum(
#' columns_to_average = c("cyl", "disp", "vs", "carb"),
#' new_column_name = "engine_sum"
#' )
#'
#' if (require(tidyr))
#' tidyr::billboard |>
#' row_sum(
#' pattern = "^wk\\d{1,2}$",
#' new_column_name = "week_sum",
#' threshold_proportion = .1,
#' verbose = TRUE
#' ) |>
#' dplyr::select(
#' artist,
#' date.entered,
#' week_sum,
#' )
#'
#' tidyr::billboard |>
#' row_sum(
#' pattern = "^wk\\d$",
#' new_column_name = "week_sum",
#' verbose = TRUE
#' ) |>
#' dplyr::select(
#' artist,
#' date.entered,
#' week_sum,
#' )

#' @export
row_sum <- function(
d,
columns_to_average = character(0),
pattern,
pattern = "",
new_column_name = "row_sum",
threshold_proportion = .75,
verbose = FALSE
) {
checkmate::assert_data_frame(d)
checkmate::assert_character(columns_to_average , any.missing = FALSE)
checkmate::assert_character(pattern , min.len = 0, max.len = 1)
checkmate::assert_character(pattern , len = 1)
checkmate::assert_character(new_column_name , len = 1)
checkmate::assert_double( threshold_proportion, len = 1)
checkmate::assert_logical( verbose , len = 1)
checkmate::assert_logical( verbose , len = 1)

if (length(columns_to_average) == 0L) {
columns_to_average <-
Expand Down
32 changes: 31 additions & 1 deletion man/row_sum.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 60562c8

Please sign in to comment.