-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Kevin Cazelles
committed
Dec 4, 2020
1 parent
a40b4ff
commit 9cdf11b
Showing
7 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#' Paste element and add elememt separators. | ||
#' | ||
#' @param x vector of to be coerced to character strings (see [paste()]). | ||
#' @param comma element separator. | ||
#' @param and last element separator (for 3 elements in `x` and more). | ||
#' | ||
#' @export | ||
#' @examples | ||
#' commaAnd(c("Judith", "Peter", "Rebecca")) | ||
|
||
commaAnd <- function(x, comma = ", ", and = " and ") { | ||
if (length(x) > 1) { | ||
paste0(paste(x[-length(x)], collapse = comma), and, x[length(x)]) | ||
} else x | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
context("commaAnd") | ||
|
||
|
||
test_that("commaAnd works", { | ||
expect_equal(commaAnd(c("J")), "J") | ||
expect_equal(commaAnd(c("J", "P")), "J and P") | ||
expect_equal(commaAnd(c("J", "P", "R")), "J, P and R") | ||
expect_equal(commaAnd(c("J", "P", "R", "M")), "J, P, R and M") | ||
expect_equal(commaAnd(c("J", "P", "R"), " and ", " and finally "), "J and P and finally R") | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters