From ed9484985c23276130326bb84b55af723f5a5c4a Mon Sep 17 00:00:00 2001 From: brendad8 <72055001+brendad8@users.noreply.github.com> Date: Mon, 13 May 2024 10:48:29 -0700 Subject: [PATCH 1/2] modify give_candygrams function --- R/give_candygrams.R | 12 ++++++++---- README.Rmd | 5 ++++- README.md | 13 +++++++++---- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/R/give_candygrams.R b/R/give_candygrams.R index 8d71397..352dabe 100644 --- a/R/give_candygrams.R +++ b/R/give_candygrams.R @@ -6,7 +6,7 @@ #' #' @return A candy gram announcement #' -#' @importFrom stringr str_detect str_to_title +#' @importFrom stringr str_detect str_to_title str_trim #' @importFrom english as.english #' #' @export @@ -21,16 +21,20 @@ give_candygrams <- function(person, number, } - if (is.null(extra_message)) { + if (is.null(extra_message)) { extra_message <- add_commentary(person, number) - + } else { + extra_message <- glue::glue("{extra_message} {add_commentary(person, number)}") } + + + number <- str_to_title(as.english(number)) - glue::glue("{number} for {person}.") + glue::glue("{number} for {person}.") + " " + stringr::str_trim(extra_message) diff --git a/README.Rmd b/README.Rmd index d101a20..64d4815 100644 --- a/README.Rmd +++ b/README.Rmd @@ -108,4 +108,7 @@ give_candygrams("Glen Coco", 4) give_candygrams("Gretchen Weiners", 4) ``` - +```{r} +give_candygrams("Glen Coco", 4, + extra_message = "Happy Birthday.") +``` diff --git a/README.md b/README.md index 876c029..7fb8326 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,6 @@ # meangirls - The goal of meangirls is to create quotes in the style of the 2004 @@ -92,7 +91,7 @@ You can also give extra commentary to your announcement: ``` r give_candygrams("Taylor Zimmerman", 2, extra_message = "Merry Christmas!") -#> Two for Taylor Zimmerman. +#> Two for Taylor Zimmerman. Merry Christmas! ``` Some special cases trigger automatic extra commentary or special @@ -100,10 +99,16 @@ behavior: ``` r give_candygrams("Glen Coco", 4) -#> Four for Glen Coco. +#> Four for Glen Coco. You go, Glen Coco! ``` ``` r give_candygrams("Gretchen Weiners", 4) -#> [1] "None for Grethen Weiners." +#> None for Gretchen Weiners. +``` + +``` r +give_candygrams("Glen Coco", 4, + extra_message = "Happy Birthday.") +#> Four for Glen Coco. Happy Birthday. You go, Glen Coco! ``` From b4d4f2f63aad3efa058585660b02e114b3a5feb5 Mon Sep 17 00:00:00 2001 From: brendad8 <72055001+brendad8@users.noreply.github.com> Date: Mon, 13 May 2024 11:00:30 -0700 Subject: [PATCH 2/2] fix give_candygrams tests --- R/give_candygrams.R | 2 +- README.md | 8 ++++---- tests/testthat/test-give_candygrams.R | 4 ++-- tests/testthat/testthat-problems.rds | Bin 0 -> 3077 bytes 4 files changed, 7 insertions(+), 7 deletions(-) create mode 100644 tests/testthat/testthat-problems.rds diff --git a/R/give_candygrams.R b/R/give_candygrams.R index 352dabe..257f472 100644 --- a/R/give_candygrams.R +++ b/R/give_candygrams.R @@ -34,7 +34,7 @@ give_candygrams <- function(person, number, number <- str_to_title(as.english(number)) - glue::glue("{number} for {person}.") + " " + stringr::str_trim(extra_message) + stringr::str_trim(glue::glue("{number} for {person}.") + " " + extra_message) diff --git a/README.md b/README.md index 7fb8326..aec9184 100644 --- a/README.md +++ b/README.md @@ -81,7 +81,7 @@ number of candygrams a person gets. ``` r give_candygrams("Taylor Zimmerman", 2) -#> Two for Taylor Zimmerman. +#> [1] "Two for Taylor Zimmerman." ``` ### Extra comments @@ -91,7 +91,7 @@ You can also give extra commentary to your announcement: ``` r give_candygrams("Taylor Zimmerman", 2, extra_message = "Merry Christmas!") -#> Two for Taylor Zimmerman. Merry Christmas! +#> [1] "Two for Taylor Zimmerman. Merry Christmas!" ``` Some special cases trigger automatic extra commentary or special @@ -99,7 +99,7 @@ behavior: ``` r give_candygrams("Glen Coco", 4) -#> Four for Glen Coco. You go, Glen Coco! +#> [1] "Four for Glen Coco. You go, Glen Coco!" ``` ``` r @@ -110,5 +110,5 @@ give_candygrams("Gretchen Weiners", 4) ``` r give_candygrams("Glen Coco", 4, extra_message = "Happy Birthday.") -#> Four for Glen Coco. Happy Birthday. You go, Glen Coco! +#> [1] "Four for Glen Coco. Happy Birthday. You go, Glen Coco!" ``` diff --git a/tests/testthat/test-give_candygrams.R b/tests/testthat/test-give_candygrams.R index 56fd4f3..5442ae2 100644 --- a/tests/testthat/test-give_candygrams.R +++ b/tests/testthat/test-give_candygrams.R @@ -1,7 +1,7 @@ test_that("add_commentary compliments people with lots of grams", { - correct_result <- "You go, Glen Coco!" + correct_result <- "Four for Glen Coco. You go, Glen Coco!" - my_result <- add_commentary("Glen Coco", 4) + my_result <- give_candygrams("Glen Coco", 4) expect_equal(my_result, correct_result) }) diff --git a/tests/testthat/testthat-problems.rds b/tests/testthat/testthat-problems.rds new file mode 100644 index 0000000000000000000000000000000000000000..d6b55c7202faac0c16e74b985cb02af01b611e67 GIT binary patch literal 3077 zcmV+g4EpmQiwFP!000001MOPfa}>uBAL$N(BqSXovMmH?ISWe)5&|M&hmU{|!UYAA zEeRV;>|?oGiL*|(=e-q@0;C*&#g&R(##Kp~IQSt|iBtF`apHuBeE5ONOXAoMiL2s= zl=HwJko*B5Gq?S_?On|p2}D&$q^j0$uYcP;Gd;6?d((5GMhHhjLA!}w)9!V z6jn(|NU0EUQ7!TM>8ZJtV-=@!?r9@$yN31Lw3#zp+c=%J9mh($V7Jz6@7ZolWs6g$ zn?7q5Yi3Vve|ndZJZVq2J64yG%TCJwj%DU@b4J0jTz9U^7%($)Ta8iMn6sx1bHcH# zeTE?|4EJm{KdH3RmW;?D+3ri$%-ym9&wo;mtxk?*m6VlIVuYP^-ASLN#4Fj@R~DW0 zcs6Ir%ee6V{w3w#6tWF;O%gDzoXLa&xxeRl(Q=ACXB;b^G4pBJOL<{AJqNAgq-z&? zM#uWc`g*tbOj%}rBJ1ReJ+4)Bz5ni6(~W3pMJ}7SiqzN!QYMvAN?COzy?~@BATzcz zSxj~r=jl#C_^@FF=hN8Jy`azr-Lx4-dA%qPfyO(M$|l(vvgtGoYqp?TF0HMOvV*Qr zmta_VG3)}^%Eq0~rma-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