diff --git a/R/assert_count_true.R b/R/assert_count_true.R index bd21256..3777931 100644 --- a/R/assert_count_true.R +++ b/R/assert_count_true.R @@ -8,6 +8,16 @@ #' dplyr::mutate( #' big_values = assert_count_true(A > 2, n = 3) #' ) +#' +#' my_data <- data.frame(name = c("Bill", "Sam"), birthdate = c("2024-05-22", "2024-05-22")) +#' my_data |> +#' dplyr::mutate( +#' birthdate = +#' dplyr::case_when( +#' assert_count_true(name == "Bill" & birthdate == "2024-05-22") ~ "2024-05-23", +#' TRUE ~ birthdate +#' ) +#' ) #' @export assert_count_true <- function(x, n = 1) { stopifnot(is.logical(x)) diff --git a/_pkgdown.yml b/_pkgdown.yml index 965f464..7d96cb0 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -5,11 +5,11 @@ template: reference: - title: Cleaning data - + - subtitle: Cleaning variable names contents: - contains("clean_names") - + - title: Exploring data desc: > tabyls are an enhanced version of tables. See `vignette("tabyls")` @@ -19,7 +19,7 @@ reference: - starts_with("adorn") - contains("tabyl") - -contains('.test') - + - subtitle: Change order contents: - row_to_names @@ -30,6 +30,7 @@ reference: Compare data frames columns contents: - starts_with("compare_df_cols") + - assert_count_true - title: Removing unnecessary columns / rows contents: @@ -38,9 +39,9 @@ reference: - get_one_to_one - top_levels - single_value - + - title: Rounding / dates helpers - desc: > + desc: > Help to mimic some behaviour from Excel or SAS. These should be used on vector. contents: diff --git a/man/assert_count_true.Rd b/man/assert_count_true.Rd index 46db969..c158760 100644 --- a/man/assert_count_true.Rd +++ b/man/assert_count_true.Rd @@ -22,4 +22,14 @@ data.frame(A = 1:5) \%>\% dplyr::mutate( big_values = assert_count_true(A > 2, n = 3) ) + +my_data <- data.frame(name = c("Bill", "Sam"), birthdate = c("2024-05-22", "2024-05-22")) +my_data |> + dplyr::mutate( + birthdate = + dplyr::case_when( + assert_count_true(name == "Bill" & birthdate == "2024-05-22") ~ "2024-05-23", + TRUE ~ birthdate + ) + ) }