From b80e2c2c113b46a6df43412d75817e69ec9b503a Mon Sep 17 00:00:00 2001 From: GenghisKhandybar Date: Mon, 13 May 2024 11:03:35 -0700 Subject: [PATCH 1/5] Fixed give_candygrams --- R/give_candygrams.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/give_candygrams.R b/R/give_candygrams.R index 8d71397..67cadcb 100644 --- a/R/give_candygrams.R +++ b/R/give_candygrams.R @@ -30,7 +30,7 @@ give_candygrams <- function(person, number, number <- str_to_title(as.english(number)) - glue::glue("{number} for {person}.") + glue::glue("{number} for {person}. {extra_message}") From e31887d606e4fc5fac7ac1795dfd3c5afe399f30 Mon Sep 17 00:00:00 2001 From: GenghisKhandybar Date: Mon, 13 May 2024 11:40:05 -0700 Subject: [PATCH 2/5] Fix really_pretty --- R/compliments.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/compliments.R b/R/compliments.R index e0066f2..bffdae0 100644 --- a/R/compliments.R +++ b/R/compliments.R @@ -7,9 +7,9 @@ #' @return A compliment string #' #' @export -really_pretty <- function(name, follow_up = TRUE) { +really_pretty <- function(name, follow_up = FALSE) { - compliment <- glue::glue("You're, like, really pretty, {name}.") + compliment <- glue::glue("You're, like, really pretty {name}.") if (follow_up) { compliment <- paste(compliment, From eb1e8d7c29b8d216492934f0f0230bdab9d7da1d Mon Sep 17 00:00:00 2001 From: GenghisKhandybar Date: Mon, 13 May 2024 11:57:28 -0700 Subject: [PATCH 3/5] Added give many candygrams --- DESCRIPTION | 2 +- NAMESPACE | 1 + R/give_candygrams.R | 3 ++- R/give_many_candygrams.R | 27 +++++++++++++++++++++++++++ README.Rmd | 3 +++ man/give_many_candygrams.Rd | 21 +++++++++++++++++++++ 6 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 R/give_many_candygrams.R create mode 100644 man/give_many_candygrams.Rd diff --git a/DESCRIPTION b/DESCRIPTION index d58c2fe..1af4346 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -19,6 +19,6 @@ Imports: glue, stringr, english -RoxygenNote: 7.1.2 +RoxygenNote: 7.3.1 Suggests: testthat (>= 2.1.0) diff --git a/NAMESPACE b/NAMESPACE index cc05d6b..c29e467 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -6,5 +6,6 @@ export(give_candygrams) export(nice_style) export(really_pretty) importFrom(english,as.english) +importFrom(purrr,pmap) importFrom(stringr,str_detect) importFrom(stringr,str_to_title) diff --git a/R/give_candygrams.R b/R/give_candygrams.R index 67cadcb..a3a7a7f 100644 --- a/R/give_candygrams.R +++ b/R/give_candygrams.R @@ -30,7 +30,7 @@ give_candygrams <- function(person, number, number <- str_to_title(as.english(number)) - glue::glue("{number} for {person}. {extra_message}") + glue::glue("{number} for {person}.{extra_message}") @@ -61,3 +61,4 @@ add_commentary <- function(person, number) { return("") } + diff --git a/R/give_many_candygrams.R b/R/give_many_candygrams.R new file mode 100644 index 0000000..565e566 --- /dev/null +++ b/R/give_many_candygrams.R @@ -0,0 +1,27 @@ +#' Gives Multiple Candygrams +#' @param students The a vector of student names +#' @param number The number of candygrams each student received +#' @param extra_messages Extra commentary for each candygram +#' +#' @return A vector of candygram announcements +#' +#' @importFrom purrr pmap +#' +#' @export + +give_many_candygrams <- function(students, counts, extra_messages = NULL){ + if(length(students) <= 1) { + print(length(students)) + stop("Must input more than 1 candygram.") + } + if(length(students) != length(counts) | + (!is.null(extra_messages) & length(students) != length(extra_messages))){ + stop("Vector lengths do not match.") + } + if(!is.null(extra_messages)){ + purrr::pmap(.l = list(students, counts, extra_messages), + .f = give_candygrams) + } + purrr::pmap(.l = list(students, counts), + .f = give_candygrams) +} diff --git a/README.Rmd b/README.Rmd index d101a20..05112ef 100644 --- a/README.Rmd +++ b/README.Rmd @@ -108,4 +108,7 @@ give_candygrams("Glen Coco", 4) give_candygrams("Gretchen Weiners", 4) ``` +```{r} +give_many_candygrams(c("Bob", "Joe"), c(1,2)) +``` diff --git a/man/give_many_candygrams.Rd b/man/give_many_candygrams.Rd new file mode 100644 index 0000000..be033fd --- /dev/null +++ b/man/give_many_candygrams.Rd @@ -0,0 +1,21 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/give_many_candygrams.R +\name{give_many_candygrams} +\alias{give_many_candygrams} +\title{Gives Multiple Candygrams} +\usage{ +give_many_candygrams(students, counts, extra_messages = NULL) +} +\arguments{ +\item{students}{The a vector of student names} + +\item{extra_messages}{Extra commentary for each candygram} + +\item{number}{The number of candygrams each student received} +} +\value{ +A vector of candygram announcements +} +\description{ +Gives Multiple Candygrams +} From 6a7c205c9895623ea151d534d63a421dcc872f7b Mon Sep 17 00:00:00 2001 From: GenghisKhandybar Date: Mon, 13 May 2024 18:31:48 -0700 Subject: [PATCH 4/5] Switched to vector outputs --- R/give_many_candygrams.R | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/R/give_many_candygrams.R b/R/give_many_candygrams.R index 565e566..bcab9be 100644 --- a/R/give_many_candygrams.R +++ b/R/give_many_candygrams.R @@ -1,4 +1,5 @@ #' Gives Multiple Candygrams +#' #' @param students The a vector of student names #' @param number The number of candygrams each student received #' @param extra_messages Extra commentary for each candygram @@ -9,7 +10,11 @@ #' #' @export -give_many_candygrams <- function(students, counts, extra_messages = NULL){ +give_many_candygrams <- function(students, counts, + extra_messages = NULL){ + # Checks: + # Length above 1 + # Equal lengths if(length(students) <= 1) { print(length(students)) stop("Must input more than 1 candygram.") @@ -18,10 +23,12 @@ give_many_candygrams <- function(students, counts, extra_messages = NULL){ (!is.null(extra_messages) & length(students) != length(extra_messages))){ stop("Vector lengths do not match.") } + + # If given extra_messages, use them if(!is.null(extra_messages)){ - purrr::pmap(.l = list(students, counts, extra_messages), + purrr::pmap_chr(.l = list(students, counts, extra_messages), .f = give_candygrams) } - purrr::pmap(.l = list(students, counts), + purrr::pmap_chr(.l = list(students, counts), .f = give_candygrams) } From 6bc4e2515960c22be5abaa6115bdfbadb7fd6aac Mon Sep 17 00:00:00 2001 From: GenghisKhandybar Date: Mon, 13 May 2024 18:32:19 -0700 Subject: [PATCH 5/5] Rebuilt --- NAMESPACE | 1 + man/really_pretty.Rd | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/NAMESPACE b/NAMESPACE index c29e467..1748b5e 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -3,6 +3,7 @@ export(boo) export(fetch) export(give_candygrams) +export(give_many_candygrams) export(nice_style) export(really_pretty) importFrom(english,as.english) diff --git a/man/really_pretty.Rd b/man/really_pretty.Rd index 84b5371..0f0749a 100644 --- a/man/really_pretty.Rd +++ b/man/really_pretty.Rd @@ -4,7 +4,7 @@ \alias{really_pretty} \title{Tells someone they are pretty.} \usage{ -really_pretty(name, follow_up = TRUE) +really_pretty(name, follow_up = FALSE) } \arguments{ \item{name}{The person's name}