From 6596b52a24a116a212405effc3ca9f04e554a50d Mon Sep 17 00:00:00 2001 From: Ben Kates Date: Sun, 31 May 2020 19:49:48 -0400 Subject: [PATCH 1/8] added offset to random_text --- R/Text.R | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/R/Text.R b/R/Text.R index cf62412..29d5c37 100644 --- a/R/Text.R +++ b/R/Text.R @@ -9,7 +9,7 @@ #' #' @export -random_text <- function(nchars = NULL, nwords = NULL){ +random_text <- function(nchars = NULL, nwords = NULL,offset=0){ stop_if_all( c(nchars, nwords), is.null, @@ -24,12 +24,14 @@ random_text <- function(nchars = NULL, nwords = NULL){ if (!is.null(nchars)){ res <- substr( shinipsum::lorem, - 1, - nchars + 1+offset, + nchars+offset ) } else { - res <- paste(shinipsum::lorem_words[1:nwords], collapse = " ") + res <- paste(shinipsum::lorem_words[1+offset:nwords+offset], collapse = " ") } + + substr(res, 1, 1) <- toupper(substr(res, 1, 1)) res } From d4622a9fd78e775f4ed551a975db8833a323a152 Mon Sep 17 00:00:00 2001 From: Ben Kates Date: Sun, 31 May 2020 19:51:47 -0400 Subject: [PATCH 2/8] fixed space and added comment --- R/Text.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/Text.R b/R/Text.R index 29d5c37..643d7ab 100644 --- a/R/Text.R +++ b/R/Text.R @@ -9,7 +9,7 @@ #' #' @export -random_text <- function(nchars = NULL, nwords = NULL,offset=0){ +random_text <- function(nchars = NULL, nwords = NULL, offset=0){ stop_if_all( c(nchars, nwords), is.null, From c222bfe308c6019f9bf80f65eab24f4583e72b08 Mon Sep 17 00:00:00 2001 From: Ben Kates Date: Sun, 31 May 2020 19:54:41 -0400 Subject: [PATCH 3/8] added roxygen comment --- R/Text.R | 1 + 1 file changed, 1 insertion(+) diff --git a/R/Text.R b/R/Text.R index 643d7ab..fa8bde6 100644 --- a/R/Text.R +++ b/R/Text.R @@ -2,6 +2,7 @@ #' #' @param nchars number of characters. One of the two params should be left NULL. #' @param nwords number of words to return. One of the two params should be left NULL. +#' @param offset number of characters or words to offset the result by. Defaults to 0. #' #' @importFrom attempt stop_if_all #' From be3f8d6df24c083ba785b87d6fb90b9c3046f493 Mon Sep 17 00:00:00 2001 From: Ben Kates Date: Sun, 31 May 2020 20:10:17 -0400 Subject: [PATCH 4/8] added test --- tests/testthat/test-text.R | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/tests/testthat/test-text.R b/tests/testthat/test-text.R index 8e3eade..fb3024f 100644 --- a/tests/testthat/test-text.R +++ b/tests/testthat/test-text.R @@ -37,3 +37,35 @@ test_that("nchar works", { ) }) }) + + +test_that("offset works", { + lapply( + 1:100, function(x){ + expect_nchar( + random_text(nchars = 10,offset = 10), + 10 + ) + expect_nchar( + random_text(nchars = 100,offset = 20), + 100 + ) + expect_nchar( + random_text(nchars = 42,offset = 20), + 42 + ) + + expect_nchar( + random_text(nwords = 12,offset = 20), + 51 + ) + expect_nchar( + random_text(nwords = 100,offset = 20), + 526 + ) + expect_nchar( + random_text(nwords = 800,offset = 20), + 5105 + ) + }) +}) From 20fc53312e0d37663a1279a6f3eec4afb860f50c Mon Sep 17 00:00:00 2001 From: Ben Kates Date: Sun, 31 May 2020 20:10:54 -0400 Subject: [PATCH 5/8] test fix --- tests/testthat/test-text.R | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/testthat/test-text.R b/tests/testthat/test-text.R index fb3024f..603936f 100644 --- a/tests/testthat/test-text.R +++ b/tests/testthat/test-text.R @@ -38,7 +38,6 @@ test_that("nchar works", { }) }) - test_that("offset works", { lapply( 1:100, function(x){ From e44c8edb7bced992bbc184e729f91dcf6ce03083 Mon Sep 17 00:00:00 2001 From: Ben Kates Date: Sun, 31 May 2020 20:14:02 -0400 Subject: [PATCH 6/8] fix space in test --- tests/testthat/test-text.R | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/testthat/test-text.R b/tests/testthat/test-text.R index 603936f..10a9a95 100644 --- a/tests/testthat/test-text.R +++ b/tests/testthat/test-text.R @@ -42,28 +42,28 @@ test_that("offset works", { lapply( 1:100, function(x){ expect_nchar( - random_text(nchars = 10,offset = 10), + random_text(nchars = 10, offset = 10), 10 ) expect_nchar( - random_text(nchars = 100,offset = 20), + random_text(nchars = 100, offset = 20), 100 ) expect_nchar( - random_text(nchars = 42,offset = 20), + random_text(nchars = 42, offset = 20), 42 ) expect_nchar( - random_text(nwords = 12,offset = 20), + random_text(nwords = 12, offset = 20), 51 ) expect_nchar( - random_text(nwords = 100,offset = 20), + random_text(nwords = 100, offset = 20), 526 ) expect_nchar( - random_text(nwords = 800,offset = 20), + random_text(nwords = 800, offset = 20), 5105 ) }) From cda8905d3c9e8a45643d2c9a08cecfea587b9998 Mon Sep 17 00:00:00 2001 From: Ben Kates Date: Mon, 8 Jun 2020 20:26:12 -0400 Subject: [PATCH 7/8] fixed test --- tests/testthat/test-text.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/testthat/test-text.R b/tests/testthat/test-text.R index 10a9a95..3049593 100644 --- a/tests/testthat/test-text.R +++ b/tests/testthat/test-text.R @@ -25,15 +25,15 @@ test_that("nchar works", { expect_nchar( random_text(nwords = 12), - 83 + 86 ) expect_nchar( random_text(nwords = 100), - 643 + 650 ) expect_nchar( random_text(nwords = 800), - 5239 + 5244 ) }) }) From db9979a723e54664d65b2189bedd66971f5b6627 Mon Sep 17 00:00:00 2001 From: Ben Kates Date: Tue, 9 Jun 2020 08:57:03 -0400 Subject: [PATCH 8/8] had to rerun the documentation --- man/random_text.Rd | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/man/random_text.Rd b/man/random_text.Rd index 4c2107b..2807a5e 100644 --- a/man/random_text.Rd +++ b/man/random_text.Rd @@ -4,12 +4,14 @@ \alias{random_text} \title{A Random Lorem Ipsum} \usage{ -random_text(nchars = NULL, nwords = NULL) +random_text(nchars = NULL, nwords = NULL, offset = 0) } \arguments{ \item{nchars}{number of characters. One of the two params should be left NULL.} \item{nwords}{number of words to return. One of the two params should be left NULL.} + +\item{offset}{number of characters or words to offset the result by. Defaults to 0.} } \value{ a text