From 030a03db7801ec25058d5d7ee5e80bf079916ab7 Mon Sep 17 00:00:00 2001 From: Bill Denney Date: Wed, 22 May 2024 10:16:14 -0400 Subject: [PATCH] Fix pkgdown; add another example --- R/assert_count_true.R | 10 ++++++++++ _pkgdown.yml | 11 ++++++----- man/assert_count_true.Rd | 10 ++++++++++ 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/R/assert_count_true.R b/R/assert_count_true.R index bd212568..37779315 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 965f4647..7d96cb04 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 46db9697..c158760e 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 + ) + ) }