├── NEWS.md ├── README.md ├── .gitignore ├── .travis.yml ├── inst ├── NEWS.md ├── README.Rmd └── README.md ├── LICENSE ├── tests ├── testthat.R └── testthat │ ├── helper.R │ └── test.R ├── NAMESPACE ├── R ├── smiley.R ├── rpackage.R ├── exclamation.R ├── verb.R ├── adverb.R ├── adjective.R └── package.R ├── .Rbuildignore ├── Makefile ├── praise.Rproj ├── DESCRIPTION ├── man ├── praise.Rd └── praise_parts.Rd └── appveyor.yml /NEWS.md: -------------------------------------------------------------------------------- 1 | inst/NEWS.md -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | inst/README.md -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .Rproj.user 2 | .Rhistory 3 | .RData 4 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: r 2 | sudo: false 3 | cache: packages 4 | -------------------------------------------------------------------------------- /inst/NEWS.md: -------------------------------------------------------------------------------- 1 | 2 | # 1.0.0 3 | 4 | First public release. 5 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | YEAR: 2015 2 | COPYRIGHT HOLDER: Gabor Csardi, Sindre Sorhus 3 | -------------------------------------------------------------------------------- /tests/testthat.R: -------------------------------------------------------------------------------- 1 | library(testthat) 2 | library(praise) 3 | 4 | test_check("praise") 5 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | export(praise) 4 | export(praise_parts) 5 | -------------------------------------------------------------------------------- /R/smiley.R: -------------------------------------------------------------------------------- 1 | 2 | smiley <- c( 3 | ":)", 4 | ":D", 5 | ":-D", 6 | ";)", 7 | "(-:", 8 | "B-)" 9 | ) 10 | -------------------------------------------------------------------------------- /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^.*\.Rproj$ 2 | ^\.Rproj\.user$ 3 | ^Makefile$ 4 | ^README.md$ 5 | ^NEWS.md$ 6 | ^.travis.yml$ 7 | ^appveyor.yml$ 8 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | 2 | all: inst/README.md 3 | 4 | inst/README.md: inst/README.Rmd 5 | Rscript -e "library(knitr); knit('$<', output = '$@', quiet = TRUE)" 6 | -------------------------------------------------------------------------------- /R/rpackage.R: -------------------------------------------------------------------------------- 1 | 2 | rpackage <- c( 3 | "code", 4 | "library (or package?)", 5 | "package", 6 | "program", 7 | "project", 8 | "software", 9 | "R package" 10 | ) 11 | -------------------------------------------------------------------------------- /praise.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | 3 | RestoreWorkspace: Default 4 | SaveWorkspace: Default 5 | AlwaysSaveHistory: Default 6 | 7 | EnableCodeIndexing: Yes 8 | UseSpacesForTab: Yes 9 | NumSpacesForTab: 2 10 | Encoding: UTF-8 11 | 12 | RnwWeave: Sweave 13 | LaTeX: pdfLaTeX 14 | 15 | AutoAppendNewline: Yes 16 | 17 | BuildType: Package 18 | PackageUseDevtools: Yes 19 | PackageInstallArgs: --no-multiarch --with-keep.source 20 | PackageRoxygenize: rd,collate,namespace,vignette 21 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: praise 2 | Title: Praise Users 3 | Version: 1.0.0 4 | Author: Gabor Csardi, Sindre Sorhus 5 | Maintainer: Gabor Csardi 6 | Description: Build friendly R packages that 7 | praise their users if they have done something 8 | good, or they just need it to feel better. 9 | License: MIT + file LICENSE 10 | LazyData: true 11 | URL: https://github.com/rladies/praise 12 | BugReports: https://github.com/rladies/praise/issues 13 | Suggests: 14 | testthat 15 | Collate: 16 | 'adjective.R' 17 | 'adverb.R' 18 | 'exclamation.R' 19 | 'verb.R' 20 | 'smiley.R' 21 | 'rpackage.R' 22 | 'package.R' 23 | RoxygenNote: 5.0.1.9000 24 | -------------------------------------------------------------------------------- /R/exclamation.R: -------------------------------------------------------------------------------- 1 | 2 | exclamation <- c( 3 | "ah", 4 | "aha", 5 | "ahh", 6 | "ahhh", 7 | "aw", 8 | "aww", 9 | "awww", 10 | "amazeballs", 11 | "aye", 12 | "booyeah", 13 | "cowabunga", 14 | "gee", 15 | "ha", 16 | "hah", 17 | "hmm", 18 | "ho-ho", 19 | "huh", 20 | "heh", 21 | "hooah", 22 | "hooray", 23 | "hurrah", 24 | "hurray", 25 | "huzzah", 26 | "mhm", 27 | "mm", 28 | "mmh", 29 | "mmhm", 30 | "mmm", 31 | "oh", 32 | "ole", 33 | "ooh", 34 | "uh-hu", 35 | "wee", 36 | "whee", 37 | "whoa", 38 | "wow", 39 | "wowie", 40 | "yahoo", 41 | "yay", 42 | "yeah", 43 | "yeahyah", 44 | "yee-haw", 45 | "yikes", 46 | "yippie", 47 | "yow", 48 | "yowza" 49 | ) 50 | -------------------------------------------------------------------------------- /R/verb.R: -------------------------------------------------------------------------------- 1 | 2 | created <- c( 3 | "assembled", 4 | "brewed", 5 | "built", 6 | "created", 7 | "composed", 8 | "constructed", 9 | "designed", 10 | "devised", 11 | "done", 12 | "forged", 13 | "formed", 14 | "initiated", 15 | "invented", 16 | "made", 17 | "organized", 18 | "planned", 19 | "prepared", 20 | "set up", 21 | "thrown together" 22 | ) 23 | 24 | creating <- c( 25 | "assembling", 26 | "brewing", 27 | "building", 28 | "creating", 29 | "composing", 30 | "constructing", 31 | "designing", 32 | "devising", 33 | "forging", 34 | "forming", 35 | "initiating", 36 | "inventing", 37 | "making", 38 | "organizing", 39 | "planning", 40 | "preparing", 41 | "setting up" 42 | ) 43 | -------------------------------------------------------------------------------- /man/praise.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/package.R 3 | \docType{package} 4 | \name{praise} 5 | \alias{praise} 6 | \alias{praise-package} 7 | \title{Praise Users} 8 | \usage{ 9 | praise(template = "You are ${adjective}!") 10 | } 11 | \arguments{ 12 | \item{template}{Character scalar, the template string.} 13 | } 14 | \description{ 15 | Build friendly R packages that 16 | praise their users if they have done something 17 | good, or they just need it to feel better. 18 | 19 | Randomized praise based on a template 20 | } 21 | \details{ 22 | Replace parts of the template with random words from the praise 23 | word lists. See examples below. 24 | } 25 | \examples{ 26 | praise() 27 | 28 | ## Capitalization 29 | praise("${Exclamation}! This ${rpackage} is ${adjective}!") 30 | 31 | ## All upper case 32 | praise("${EXCLAMATION}! You have done this ${adverb_manner}!") 33 | } 34 | 35 | -------------------------------------------------------------------------------- /man/praise_parts.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/package.R 3 | \docType{data} 4 | \name{praise_parts} 5 | \alias{praise_parts} 6 | \title{Parts of speech for praising} 7 | \format{Named list of character vertors. List entries: \describe{ 8 | \item{adjective}{Words and phrases to be used as positive adjectives. 9 | Most of them are from \url{https://github.com/sindresorhus/superb}.} 10 | \item{adverb}{Adverbs.} 11 | \item{adverb_manner}{Adverbs of manner, with positive meanings.} 12 | \item{created}{Synonyms of \sQuote{create} in paste tense.} 13 | \item{creating}{Synonyms of \sQuote{create}, in present participle 14 | form.} 15 | \item{exclamation}{Positive exclamations.} 16 | \item{rpackage}{Synonyms for the term \sQuote{R package}.} 17 | }} 18 | \usage{ 19 | praise_parts 20 | } 21 | \description{ 22 | Parts of speech for praising 23 | } 24 | \keyword{datasets} 25 | 26 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | # DO NOT CHANGE the "init" and "install" sections below 2 | 3 | # Download script file from GitHub 4 | init: 5 | ps: | 6 | $ErrorActionPreference = "Stop" 7 | Invoke-WebRequest http://raw.github.com/krlmlr/r-appveyor/master/scripts/appveyor-tool.ps1 -OutFile "..\appveyor-tool.ps1" 8 | Import-Module '..\appveyor-tool.ps1' 9 | 10 | install: 11 | ps: Bootstrap 12 | 13 | # Adapt as necessary starting from here 14 | 15 | build_script: 16 | - travis-tool.sh install_deps 17 | 18 | test_script: 19 | - travis-tool.sh run_tests 20 | 21 | on_failure: 22 | - travis-tool.sh dump_logs 23 | 24 | artifacts: 25 | - path: '*.Rcheck\**\*.log' 26 | name: Logs 27 | 28 | - path: '*.Rcheck\**\*.out' 29 | name: Logs 30 | 31 | - path: '*.Rcheck\**\*.fail' 32 | name: Logs 33 | 34 | - path: '*.Rcheck\**\*.Rout' 35 | name: Logs 36 | 37 | - path: '\*_*.tar.gz' 38 | name: Bits 39 | 40 | - path: '\*_*.zip' 41 | name: Bits 42 | -------------------------------------------------------------------------------- /R/adverb.R: -------------------------------------------------------------------------------- 1 | 2 | adverb_manner <- c( 3 | "beautifully", 4 | "bellissimo", 5 | "bigly", 6 | "bravely", 7 | "brightly", 8 | "calmly", 9 | "carefully", 10 | "cautiously", 11 | "cheerfully", 12 | "clearly", 13 | "correctly", 14 | "courageously", 15 | "daringly", 16 | "deliberately", 17 | "doubtfully", 18 | "eagerly", 19 | "easily", 20 | "effectively", 21 | "elegantly", 22 | "enormously", 23 | "enthusiastically", 24 | "faithfully", 25 | "fast", 26 | "fondly", 27 | "fortunately", 28 | "frankly", 29 | "frantically", 30 | "generously", 31 | "gently", 32 | "gladly", 33 | "gracefully", 34 | "happily", 35 | "healthily", 36 | "honestly", 37 | "joyously", 38 | "justly", 39 | "kindly", 40 | "neatly", 41 | "openly", 42 | "patiently", 43 | "perfectly", 44 | "politely", 45 | "powerfully", 46 | "quickly", 47 | "quietly", 48 | "rapidly", 49 | "really", 50 | "regularly", 51 | "repeatedly", 52 | "rightfully", 53 | "seriously", 54 | "sharply", 55 | "smoothly", 56 | "speedily", 57 | "successfully", 58 | "swiftly", 59 | "tenderly", 60 | "thoughtfully", 61 | "truthfully", 62 | "trustfully", 63 | "warmly", 64 | "well", 65 | "wisely" 66 | ) 67 | 68 | adverb <- adverb_manner 69 | -------------------------------------------------------------------------------- /tests/testthat/helper.R: -------------------------------------------------------------------------------- 1 | 2 | re_match <- function(pattern, x) { 3 | stopifnot(length(x) == 1) 4 | 5 | mat <- regexpr(pattern, x, perl = TRUE) 6 | 7 | if (mat != -1L) { 8 | res <- substring(x, mat, mat + attr(mat, "match.length") - 1L) 9 | if (length(attr(mat, "capture.start"))) { 10 | res <- c( 11 | res, 12 | substring( 13 | x, 14 | attr(mat, "capture.start"), 15 | attr(mat, "capture.start") + attr(mat, "capture.length") - 1 16 | ) 17 | ) 18 | } 19 | 20 | if (any(attr(mat, "capture.names") != "")) { 21 | names(res) <- c("", attr(mat, "capture.names")) 22 | } 23 | res 24 | 25 | } else { 26 | NULL 27 | } 28 | 29 | } 30 | 31 | praise_check <- function(template, regexp, num = 10) { 32 | 33 | for (i in 1:num) { 34 | pra <- praise(template) 35 | match <- re_match(regexp, pra) 36 | expect_true( !is.null(match), info = template ) 37 | 38 | parts <- sub("[0-9]*$", "", names(match[-1])) 39 | for (p in seq_along(parts)) { 40 | expect_true(tolower(match[p + 1]) %in% 41 | tolower(praise_parts[[ parts[p] ]])) 42 | } 43 | } 44 | } 45 | 46 | is_capitalized <- function(x) { 47 | toupper(substring(x, 1, 1)) == substring(x, 1, 1) & 48 | tolower(substring(x, 2)) == substring(x, 2) 49 | } 50 | 51 | is_all_uppercase <- function(x) { 52 | toupper(x) == x 53 | } 54 | 55 | is_all_lowercase <- function(x) { 56 | tolower(x) == x 57 | } 58 | -------------------------------------------------------------------------------- /inst/README.Rmd: -------------------------------------------------------------------------------- 1 | 2 | ```{r, setup, echo = FALSE, message = FALSE} 3 | knitr::opts_chunk$set( 4 | comment = "#>", 5 | tidy = FALSE, 6 | error = FALSE, 7 | fig.width = 8, 8 | fig.height = 8) 9 | ``` 10 | 11 | # praise 12 | 13 | > Praise Users 14 | 15 | [![Project Status: Active - The project has reached a stable, usable state and is being actively developed.](http://www.repostatus.org/badges/latest/active.svg)](http://www.repostatus.org/#active) 16 | [![Linux Build Status](https://travis-ci.org/gaborcsardi/praise.svg?branch=master)](https://travis-ci.org/gaborcsardi/praise) 17 | [![Windows Build status](https://ci.appveyor.com/api/projects/status/github/gaborcsardi/praise?svg=true)](https://ci.appveyor.com/project/gaborcsardi/praise) 18 | [![](http://www.r-pkg.org/badges/version/praise)](http://www.r-pkg.org/pkg/praise) 19 | [![CRAN RStudio mirror downloads](http://cranlogs.r-pkg.org/badges/praise)](http://www.r-pkg.org/pkg/praise) 20 | 21 | 22 | Build friendly R packages that praise their users if they have 23 | done something good, or they just need it to feel better. 24 | 25 | ## Installation 26 | 27 | ```{r eval = FALSE} 28 | # install.packages("remotes") 29 | remotes::install_github("rladies/praise") 30 | ``` 31 | 32 | ## Usage 33 | 34 | ```{r} 35 | library(praise) 36 | praise() 37 | ``` 38 | 39 | You can supply a template, and `praise()` fills in random words of the specified 40 | part of speech: 41 | 42 | ```{r} 43 | praise("${EXCLAMATION}! You have done this ${adverb_manner}!") 44 | ``` 45 | 46 | Note that capitalization in the inserted words will be the same as in the template: 47 | 48 | ```{r} 49 | praise("${Exclamation}! ${EXCLAMATION}!-${EXCLAMATION}! This is just ${adjective}!") 50 | ``` 51 | 52 | Currently supported parts of speech: 53 | 54 | ```{r} 55 | names(praise_parts) 56 | ``` 57 | 58 | ## License 59 | 60 | MIT © [Gabor Csardi](https://github.com/gaborcsardi), [Sindre Sorhus](http://sindresorhus.com) 61 | -------------------------------------------------------------------------------- /inst/README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | # praise 5 | 6 | > Praise Users 7 | 8 | [![Project Status: Active - The project has reached a stable, usable state and is being actively developed.](http://www.repostatus.org/badges/latest/active.svg)](http://www.repostatus.org/#active) 9 | [![Linux Build Status](https://travis-ci.org/gaborcsardi/praise.svg?branch=master)](https://travis-ci.org/gaborcsardi/praise) 10 | [![Windows Build status](https://ci.appveyor.com/api/projects/status/github/gaborcsardi/praise?svg=true)](https://ci.appveyor.com/project/gaborcsardi/praise) 11 | [![](http://www.r-pkg.org/badges/version/praise)](http://www.r-pkg.org/pkg/praise) 12 | [![CRAN RStudio mirror downloads](http://cranlogs.r-pkg.org/badges/praise)](http://www.r-pkg.org/pkg/praise) 13 | 14 | 15 | Build friendly R packages that praise their users if they have 16 | done something good, or they just need it to feel better. 17 | 18 | ## Installation 19 | 20 | 21 | ```r 22 | # install.packages("remotes") 23 | remotes::install_github("rladies/praise") 24 | ``` 25 | 26 | ## Usage 27 | 28 | 29 | ```r 30 | library(praise) 31 | praise() 32 | ``` 33 | 34 | ``` 35 | #> [1] "You are super-excellent!" 36 | ``` 37 | 38 | You can supply a template, and `praise()` fills in random words of the specified 39 | part of speech: 40 | 41 | 42 | ```r 43 | praise("${EXCLAMATION}! You have done this ${adverb_manner}!") 44 | ``` 45 | 46 | ``` 47 | #> [1] "AYE! You have done this enormously!" 48 | ``` 49 | 50 | Note that capitalization in the inserted words will be the same as in the template: 51 | 52 | 53 | ```r 54 | praise("${Exclamation}! ${EXCLAMATION}!-${EXCLAMATION}! This is just ${adjective}!") 55 | ``` 56 | 57 | ``` 58 | #> [1] "Yowza! MMHM!-YAHOO! This is just praiseworthy!" 59 | ``` 60 | 61 | Currently supported parts of speech: 62 | 63 | 64 | ```r 65 | names(praise_parts) 66 | ``` 67 | 68 | ``` 69 | #> [1] "adjective" "adverb" "adverb_manner" "created" 70 | #> [5] "creating" "exclamation" "rpackage" 71 | ``` 72 | 73 | ## License 74 | 75 | MIT © [Gabor Csardi](https://github.com/gaborcsardi), [Sindre Sorhus](http://sindresorhus.com) 76 | -------------------------------------------------------------------------------- /R/adjective.R: -------------------------------------------------------------------------------- 1 | adjective <- c( 2 | "ace", 3 | "adorable", 4 | "amazing", 5 | "astonishing", 6 | "astounding", 7 | "awe-inspiring", 8 | "aaahwesome", 9 | "awesome", 10 | "baboosh", 11 | "badass", 12 | "beautiful", 13 | "bedazzling", 14 | "best", 15 | "bravissimo", 16 | "breathtaking", 17 | "brightest", 18 | "brilliant", 19 | "charming", 20 | "clever", 21 | "chic", 22 | "classy", 23 | "clever", 24 | "cool", 25 | "crackin'", 26 | "cute", 27 | "dandy", 28 | "dazzling", 29 | "delicate", 30 | "delicious", 31 | "delightful", 32 | "distinctive", 33 | "divine", 34 | "dope", 35 | "dynamite", 36 | "elegant", 37 | "epic", 38 | "excellent", 39 | "exclusive", 40 | "exceptional", 41 | "exciting", 42 | "exhilarating", 43 | "exquisite", 44 | "extraordinary", 45 | "fabulous", 46 | "fancy", 47 | "fantastic", 48 | "fantabulosus", 49 | "fantabulous", 50 | "fascinating", 51 | "fine", 52 | "finest", 53 | "first-class", 54 | "first-rate", 55 | "flawless", 56 | "formidable", 57 | "funkadelic", 58 | "geometric", 59 | "glorious", 60 | "gnarly", 61 | "good", 62 | "good-looking", 63 | "gorgeous", 64 | "grand", 65 | "great", 66 | "groovy", 67 | "groundbreaking", 68 | "hip", 69 | "hot", 70 | "hunky-dory", 71 | "impeccable", 72 | "impressive", 73 | "incredible", 74 | "irresistible", 75 | "just wow", 76 | "kickass", 77 | "kryptonian", 78 | "laudable", 79 | "legendary", 80 | "lovely", 81 | "luminous", 82 | "magnificent", 83 | "magnifique", 84 | "majestic", 85 | "marvelous", 86 | "mathematical", 87 | "metal", 88 | "mind-blowing", 89 | "miraculous", 90 | "nice", 91 | "neat", 92 | "nice", 93 | "outstanding", 94 | "particular", 95 | "peachy", 96 | "peculiar", 97 | "perfect", 98 | "phenomenal", 99 | "pioneering", 100 | "polished", 101 | "praiseworthy", 102 | "premium", 103 | "priceless", 104 | "prime", 105 | "primo", 106 | "proper", 107 | "rad", 108 | "radical", 109 | "remarkable", 110 | "riveting", 111 | "rockandroll", 112 | "rockin", 113 | "sensational", 114 | "sharp", 115 | "shining", 116 | "slick", 117 | "smart", 118 | "smashing", 119 | "solid", 120 | "special", 121 | "spectacular", 122 | "spiffing", 123 | "splendery-doodley", 124 | "splendid", 125 | "splendiferous", 126 | "stellar", 127 | "sterling", 128 | "striking", 129 | "stonking", 130 | "stunning", 131 | "stupefying", 132 | "stupendous", 133 | "stylish", 134 | "sublime", 135 | "supah", 136 | "super", 137 | "super-duper", 138 | "super-excellent", 139 | "super-good", 140 | "superb", 141 | "superior", 142 | "supreme", 143 | "sweet", 144 | "sweetest", 145 | "swell", 146 | "terrific", 147 | "tiptop", 148 | "top-notch", 149 | "top-shelf", 150 | "transcendent", 151 | "tremendous", 152 | "tubular", 153 | "ultimate", 154 | "unique", 155 | "unbelievable", 156 | "unreal", 157 | "well-made", 158 | "wicked", 159 | "wise", 160 | "wonderful", 161 | "wondrous", 162 | "world-class" 163 | ) 164 | -------------------------------------------------------------------------------- /R/package.R: -------------------------------------------------------------------------------- 1 | 2 | #' @title Praise Users 3 | #' @name praise 4 | #' @description Build friendly R packages that 5 | #' praise their users if they have done something 6 | #' good, or they just need it to feel better. 7 | #' 8 | #' @docType package 9 | #' @aliases praise praise-package 10 | 11 | NULL 12 | 13 | 14 | #' Parts of speech for praising 15 | #' 16 | #' @format 17 | #' Named list of character vectors. List entries: \describe{ 18 | #' \item{adjective}{Words and phrases to be used as positive adjectives. 19 | #' Most of them are from \url{https://github.com/sindresorhus/superb}.} 20 | #' \item{adverb}{Adverbs.} 21 | #' \item{adverb_manner}{Adverbs of manner, with positive meanings.} 22 | #' \item{created}{Synonyms of \sQuote{create} in past tense.} 23 | #' \item{creating}{Synonyms of \sQuote{create}, in present participle 24 | #' form.} 25 | #' \item{exclamation}{Positive exclamations.} 26 | #' \item{rpackage}{Synonyms for the term \sQuote{R package}.} 27 | #' } 28 | #' 29 | #' @include adjective.R adverb.R exclamation.R rpackage.R smiley.R verb.R 30 | #' @export 31 | 32 | praise_parts <- list( 33 | adjective = adjective, 34 | adverb = adverb, 35 | adverb_manner = adverb_manner, 36 | created = created, 37 | creating = creating, 38 | exclamation = exclamation, 39 | rpackage = rpackage, 40 | smiley = smiley 41 | ) 42 | 43 | 44 | #' Randomized praise based on a template 45 | #' 46 | #' @details 47 | #' Replace parts of the template with random words from the praise 48 | #' word lists. See examples below. 49 | #' 50 | #' @param template Character scalar, the template string. 51 | #' @export 52 | #' @examples 53 | #' praise() 54 | #' 55 | #' ## Capitalization 56 | #' praise("${Exclamation}! This ${rpackage} is ${adjective}!") 57 | #' 58 | #' ## All upper case 59 | #' praise("${EXCLAMATION}! You have done this ${adverb_manner}!") 60 | 61 | praise <- function(template = "You are ${adjective}!") { 62 | while (is_template(template)) { 63 | template <- replace_one_template(template) 64 | } 65 | template 66 | } 67 | 68 | 69 | template_pattern <- "\\$\\{([^\\}]+)\\}" 70 | 71 | 72 | is_template <- function(x) grepl(template_pattern, x) 73 | 74 | 75 | replace_one_template <- function(template) { 76 | match <- regexpr(template_pattern, template, perl = TRUE) 77 | 78 | template1 <- substring( 79 | template, 80 | match, 81 | match + attr(match, "match.length") - 1L 82 | ) 83 | 84 | part <- substring( 85 | template, 86 | attr(match, "capture.start"), 87 | attr(match, "capture.start") + attr(match, "capture.length") - 1L 88 | ) 89 | 90 | match_case_sub( 91 | template1, 92 | part, 93 | sample(praise_parts[[tolower(part)]], 1), 94 | template 95 | ) 96 | } 97 | 98 | 99 | match_case_sub <- function(pattern, part, replacement, text) { 100 | if (toupper(part) == part) { 101 | replacement <- toupper(replacement) 102 | } else if (capitalize(part) == part) { 103 | replacement <- capitalize(replacement) 104 | } 105 | 106 | sub(pattern, replacement, text, fixed = TRUE) 107 | } 108 | 109 | capitalize <- function(x) { 110 | paste0( 111 | toupper(substring(x, 1, 1)), 112 | substring(x, 2) 113 | ) 114 | } 115 | -------------------------------------------------------------------------------- /tests/testthat/test.R: -------------------------------------------------------------------------------- 1 | 2 | context("parts") 3 | 4 | test_that("all parts are lowercase (except some)", { 5 | lower <- setdiff(names(praise_parts), "smiley") 6 | for (p in lower) { 7 | pp <- setdiff(praise_parts[[p]], "R package") 8 | expect_true( all(is_all_lowercase(pp)), info = p ) 9 | } 10 | }) 11 | 12 | context("templating") 13 | 14 | test_that("template without praise word", { 15 | 16 | str <- "This is just a random string" 17 | expect_equal(praise(str), str) 18 | 19 | expect_equal(praise(""), "") 20 | 21 | }) 22 | 23 | test_that("corner cases are OK", { 24 | praise_check("", "") 25 | praise_check("x", "x") 26 | praise_check("${adjective}", "^(?.*)$") 27 | }) 28 | 29 | test_that("template with a single part", { 30 | 31 | praise_check( 32 | "This is ${adjective}.", 33 | "^This is (?.*)\\.$" 34 | ) 35 | 36 | praise_check( 37 | "This is ${adverb}.", 38 | "^This is (?.*)\\.$" 39 | ) 40 | 41 | praise_check( 42 | "This is ${adverb_manner}.", 43 | "This is (?.*)\\.$" 44 | ) 45 | 46 | praise_check( 47 | "This was ${created}.", 48 | "^This was (?.*)\\.$" 49 | ) 50 | 51 | praise_check( 52 | "This was ${creating}.", 53 | "^This was (?.*)\\.$" 54 | ) 55 | 56 | praise_check( 57 | "This was ${exclamation}.", 58 | "^This was (?.*)\\.$" 59 | ) 60 | 61 | praise_check( 62 | "This is a nice ${rpackage}!", 63 | "^This is a nice (?.*)!$" 64 | ) 65 | 66 | }) 67 | 68 | test_that("templates with multiple parts of the same type", { 69 | 70 | praise_check("This is ${adjective} and ${adjective}.", 71 | "^This is (?.*) and (?.*)\\.$") 72 | 73 | }) 74 | 75 | test_that("different part types in the same template", { 76 | 77 | praise_check( 78 | "You did this ${adverb_manner} and it got ${adjective}!", 79 | "^You did this (?.*) and it got (?.*)!$" 80 | ) 81 | 82 | }) 83 | 84 | context("Capilatization") 85 | 86 | test_that("templates are case insensitive", { 87 | 88 | praise_check("${AdjeCtiVe}", "^(?.*)$") 89 | 90 | praise_check( 91 | "This is ${adjeCtive}.", 92 | "^This is (?.*)\\.$" 93 | ) 94 | 95 | praise_check( 96 | "This is ${Adverb}.", 97 | "^This is (?.*)\\.$" 98 | ) 99 | 100 | praise_check( 101 | "This is ${Adverb_Manner}.", 102 | "This is (?.*)\\.$" 103 | ) 104 | 105 | praise_check( 106 | "This was ${CREATED}.", 107 | "^This was (?.*)\\.$" 108 | ) 109 | 110 | praise_check( 111 | "This was ${creatING}.", 112 | "^This was (?.*)\\.$" 113 | ) 114 | 115 | praise_check( 116 | "This was ${EXClamation}.", 117 | "^This was (?.*)\\.$" 118 | ) 119 | 120 | praise_check( 121 | "This is a nice ${rpACKage}!", 122 | "^This is a nice (?.*)!$" 123 | ) 124 | 125 | praise_check("This is ${Adjective} and ${Adjective}.", 126 | "^This is (?.*) and (?.*)\\.$") 127 | 128 | praise_check( 129 | "You did this ${adVERB_manner} and it got ${Adjective}!", 130 | "^You did this (?.*) and it got (?.*)!$" 131 | ) 132 | 133 | }) 134 | 135 | test_that("first letter is capitalized", { 136 | for (i in 1:10) { 137 | pra <- praise("${Adjective}") 138 | expect_true(is_capitalized(pra)) 139 | pra <- praise("${Adverb}") 140 | expect_true(is_capitalized(pra)) 141 | pra <- praise("${Adverb_manner}") 142 | expect_true(is_capitalized(pra)) 143 | pra <- praise("${Created}") 144 | expect_true(is_capitalized(pra)) 145 | pra <- praise("${Creating}") 146 | expect_true(is_capitalized(pra)) 147 | pra <- praise("${Exclamation}") 148 | expect_true(is_capitalized(pra)) 149 | pra <- praise("${Rpackage}") 150 | expect_true(is_capitalized(pra)) 151 | } 152 | }) 153 | 154 | test_that("whole word is upper case", { 155 | for (i in 1:10) { 156 | pra <- praise("${ADJECTIVE}") 157 | expect_true(is_all_uppercase(pra), info = pra) 158 | pra <- praise("${ADVERB}") 159 | expect_true(is_all_uppercase(pra)) 160 | pra <- praise("${ADVERB_MANNER}") 161 | expect_true(is_all_uppercase(pra)) 162 | pra <- praise("${CREATED}") 163 | expect_true(is_all_uppercase(pra)) 164 | pra <- praise("${CREATING}") 165 | expect_true(is_all_uppercase(pra)) 166 | pra <- praise("${EXCLAMATION}") 167 | expect_true(is_all_uppercase(pra)) 168 | pra <- praise("${RPACKAGE}") 169 | expect_true(is_all_uppercase(pra)) 170 | } 171 | }) 172 | --------------------------------------------------------------------------------