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..1748b5e 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -3,8 +3,10 @@ export(boo) export(fetch) export(give_candygrams) +export(give_many_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/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, diff --git a/R/give_candygrams.R b/R/give_candygrams.R index 8d71397..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}.") + 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..bcab9be --- /dev/null +++ b/R/give_many_candygrams.R @@ -0,0 +1,34 @@ +#' 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){ + # Checks: + # Length above 1 + # Equal lengths + 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 given extra_messages, use them + if(!is.null(extra_messages)){ + purrr::pmap_chr(.l = list(students, counts, extra_messages), + .f = give_candygrams) + } + purrr::pmap_chr(.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 +} 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}