diff --git a/NAMESPACE b/NAMESPACE index 97cd4f0..174b693 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,11 +1,13 @@ # Generated by roxygen2: do not edit by hand export(animals) -export(bubble) +export(bubble_say) export(bubble_tail) export(bubble_tail2) +export(bubble_think) export(endless_horse) export(say) +export(think) importFrom(rlang,abort) importFrom(rlang,are_na) importFrom(rlang,arg_match) diff --git a/R/bubble.R b/R/bubble.R index 1fea268..d3376f0 100644 --- a/R/bubble.R +++ b/R/bubble.R @@ -5,35 +5,87 @@ #' @param width (integer/numeric) width of each line. default: 60 #' @return character vector of length greater than the input `x` #' @note modified from +#' @details `bubble_say` gives the traditional bubble that you get when +#' you run `cowsay` on the command line, with carrots or slashes for the +#' sides, while `bubble_think` gives a slightly different bubble with +#' parens for the sides #' @examplesIf rlang::is_installed("fortunes") #' library(fortunes) #' quote <- as.character(fortune()) -#' bubble(x = quote) +#' bubble_say(x = quote) +#' +#' cat(bubble_say(paste(quote, collapse = " ")), sep = "\n") +#' ch <- animals[["chicken"]] +#' z <- paste(c(bubble_say(quote), bubble_tail(ch, "\\"), ch), collapse = "\n") +#' cat(z) #' +#' @examplesIf rlang::is_installed("fortunes") && interactive() #' text_color <- sample(grDevices::colors(), 1) #' text_style <- crayon::make_style(text_color) -#' text_style(bubble(quote)) -#' -#' cat(bubble(paste(quote, collapse = " ")), sep = "\n") -bubble <- function(x, width = 60) { +#' text_style(bubble_say(quote)) +bubble_say <- function(x, width = 60) { + top <- bottom <- "-" + side <- "|" + empty_to_avoid_rlang_header <- "" + added_ws <- 2L + x <- strwrap(x, width = width - 4) + n <- max(nchar(x)) + m <- length(x) + top_ <- paste0(c(" ", rep(top, n + added_ws), " "), collapse = "") + bottom_ <- paste0(c(" ", rep(bottom, n + added_ws), " "), collapse = "") + slant_top <- paste0(c("/", rep(" ", n + added_ws), "\\"), collapse = "") + slant_bottom <- paste0(c("\\", rep(" ", n + added_ws), "/"), collapse = "") + quote <- rep("", m) + for (i in seq_len(m)) { + if (substr(x[i], 1, 1) != top) { + x[i] <- string_pad(x[i], nchar(x[i]) + 1, "left") + if (m == 1) { + quote[i] <- paste0("<", string_pad(x[i], n + added_ws, "right"), ">") + next + } + if (i == 1) { + quote[i] <- paste0("/", string_pad(x[i], n + added_ws, "right"), "\\") + } else if (i == length(quote)) { + quote[i] <- paste0("\\", string_pad(x[i], n + added_ws, "right"), "/") + } else { + quote[i] <- paste0(side, string_pad(x[i], n + added_ws, "right"), side) + } + } else { + quote[i] <- paste0(side, string_pad(x[i], n + added_ws, "left"), side) + } + } + c(empty_to_avoid_rlang_header, top_, quote, bottom_) +} + +#' @export +#' @rdname bubble_say +bubble_think <- function(x, width = 60) { + top <- bottom <- "-" + left <- "(" + right <- ")" empty_to_avoid_rlang_header <- "" - x <- strwrap(x, width = width) + added_ws <- 2L + x <- strwrap(x, width = width - 4) n <- max(nchar(x)) m <- length(x) - top <- bottom <- paste0(c("+", rep("-", n + 4), "+"), collapse = "") + top_ <- paste0(rep(top, n + added_ws), collapse = "") + bottom_ <- paste0(rep(bottom, n + added_ws), collapse = "") quote <- rep("", m) for (i in seq_len(m)) { - if (substr(x[i], 1, 1) != "-") { - quote[i] <- paste0("|", string_pad(x[i], n + 4, "right"), "|") + if (substr(x[i], 1, 1) != top) { + z <- string_pad(x[i], nchar(x[i]) + 1, "left") + quote[i] <- paste0(left, string_pad(z, n + added_ws, "right"), right) } else { - quote[i] <- paste0("|", string_pad(x[i], n + 4, "left"), "|") + quote[i] <- paste0(left, string_pad(x[i], n + added_ws, "left"), right) } } - c(empty_to_avoid_rlang_header, top, quote, bottom) + top_ <- string_pad(top_, nchar(top_) + 1, "both") + bottom_ <- string_pad(bottom_, nchar(bottom_) + 1, "both") + c(empty_to_avoid_rlang_header, top_, quote, bottom_) } #' Make the tail part of a thought bubble -#' +#' #' @export #' @param animal (character) a string #' @param thought_sym (character) scalar character to use for the @@ -42,12 +94,16 @@ bubble <- function(x, width = 60) { #' @param max_char_length (numeric) length of the maximum line. this is used #' to determine how much whitespace padding to add to the left of #' `thought_sym` -#' @examplesIf interactive() +#' @details `bubble_tail` uses the animal as input so that the tail is put +#' close to the top of the animal, whereas `bubble_tail2` just puts the tail +#' about a 1/3 of the way from the left most character given the max +#' character length +#' @examples #' bubble_tail(animals[["chicken"]]) #' cat(bubble_tail(animals[["chicken"]]), sep = "\n") #' cat(bubble_tail(animals[["chicken"]]), sep = "\n") #' cat(bubble_tail(animals[["chicken"]], "%"), sep = "\n") -#' +#' #' bubble_tail2(59) #' cat(bubble_tail2(59), sep = "\n") #' cat(bubble_tail2(11), sep = "\n") @@ -58,7 +114,7 @@ bubble_tail <- function(animal, thought_sym = "o") { n_first_spaces <- length(gregexpr("\\s", animal_split[1])[[1]]) c( string_pad(thought_sym, n_first_spaces - 2, "left"), - string_pad(thought_sym, (n_first_spaces - 2) + 2, "left") + string_pad(thought_sym, (n_first_spaces - 2) + 1, "left") ) } @@ -67,14 +123,20 @@ bubble_tail <- function(animal, thought_sym = "o") { bubble_tail2 <- function(max_char_length, thought_sym = "o") { c( string_pad(thought_sym, floor((max_char_length + 4) / 3), "left"), - string_pad(thought_sym, floor((max_char_length + 4) / 3) + 2, "left") + string_pad(thought_sym, floor((max_char_length + 4) / 3) + 1, "left") ) } string_pad <- function(string, n, side) { fmt <- switch(side, left = paste0("%", n, "s"), - right = paste0("%-", n, "s") + right = paste0("%-", n, "s"), + NULL ) - sprintf(fmt, string) + if (side == "both") { + string <- string_pad(string, n, "left") + string_pad(string, nchar(string) + 1, "right") + } else { + sprintf(fmt, string) + } } diff --git a/R/say.R b/R/say.R index 972154f..c011c78 100644 --- a/R/say.R +++ b/R/say.R @@ -1,3 +1,112 @@ +#' say/think factory +#' @param thought_sym (character) scalar character to use for the +#' speech bubble tail (see ). +#' default: "o" +#' @param say_or_think (character) +#' @keywords internal +say_think <- function(thought_sym, say_or_think) { + function( + what = "Hello world!", by = "cow", type = NULL, + what_color = NULL, by_color = what_color, length = 18, fortune = NULL, + width = 60, ...) { + stopifnot("what must be length 1" = has_length(what, 1)) + + if ( + crayon::has_color() == FALSE && + (!is_null(what_color) || !is_null(by_color)) + ) { + inform(c( + "Colors cannot be applied in this environment :(", + "Try using a terminal or RStudio/Positron/etc." + )) + what_color <- NULL + by_color <- NULL + } else { + what_color <- check_color(what_color) + by_color <- check_color(by_color) + } + + if (is_null(type)) { + if (interactive()) { + type <- "message" + } else { + type <- "print" + } + } + + if (what == "catfact") { + rlang::check_installed("jsonlite") + what <- jsonlite::fromJSON(catfact_api)$fact + by <- "cat" + } + + who <- get_who(by, length = length) + + if (!is_null(fortune)) { + rlang::check_installed("fortunes") + what <- "fortune" + } + + if (what == "time") { + what <- as.character(Sys.time()) + } + + if (what == "fortune") { + rlang::check_installed("fortunes") + if (is_null(fortune)) { + fortune <- sample(1:360, 1) + } + what <- as.character(fortune(which = fortune, ...)) + what <- what[!are_na(what)] # remove missing pieces (e.g. "context") + what <- gsub("", "\n", paste(what, collapse = "\n ")) + } + + if (by == "hypnotoad" && what == "Hello world!") { + what <- "All Glory to the HYPNO TOAD!" + } + + if (what == "rms") { + rlang::check_installed("rmsfact") + what <- rmsfact::rmsfact() + } + + if (what %in% fillerama_what) { + abort("sorry, fillerama API is gone, sorry :(") + } + + what_bubbled <- switch(say_or_think, + say = bubble_say(x = what, width = width), + think = bubble_think(x = what, width = width), + abort("only 'say' and 'think' supported in say_think()") + ) + what_styled <- color_text(what_bubbled, what_color) + what_tail <- bubble_tail(who, thought_sym = thought_sym) + tail_styled <- color_text(what_tail, what_color) + who_styled <- color_text(who, by_color) + what_who <- paste(c(what_styled, tail_styled, who_styled), collapse = "\n") + + if (type == "warning") { + if (nchar(what_who) < 100) { + wl <- 100 + } else if (nchar(what_who) > 8170) { + wl <- 8170 + } else { + wl <- nchar(what_who) + 1 + } + warn_op <- options(warning.length = wl) + on.exit(options(warn_op)) + } + + switch(type, + message = message(what_who), + warning = warning(what_who), + print = cat(what_who), + string = what_who + ) + } +} + + #' Sling messages and warnings with flair #' #' @export @@ -39,8 +148,6 @@ #' string which is used as a pattern passed to [grep()] (and a random one is #' selected upton multiple matches). Passed on to the `which` parameter of #' `fortunes::fortune` -#' @param thought_sym (character) scalar character to use for the -#' speech bubble tail (see ) #' @param width (integer/numeric) width of each line. default: 60 #' @param ... Further args passed on to `fortunes::fortune()` #' @@ -129,98 +236,8 @@ #' # Using the catfacts API #' library(jsonlite) #' say("catfact", "cat") -say <- function( - what = "Hello world!", by = "cow", type = NULL, - what_color = NULL, by_color = what_color, length = 18, fortune = NULL, - thought_sym = "o", width = 60, ...) { - stopifnot("what must be length 1" = has_length(what, 1)) - - if ( - crayon::has_color() == FALSE && - (!is_null(what_color) || !is_null(by_color)) - ) { - inform(c( - "Colors cannot be applied in this environment :(", - "Try using a terminal or RStudio/Positron/etc." - )) - what_color <- NULL - by_color <- NULL - } else { - what_color <- check_color(what_color) - by_color <- check_color(by_color) - } - - if (is_null(type)) { - if (interactive()) { - type <- "message" - } else { - type <- "print" - } - } - - if (what == "catfact") { - rlang::check_installed("jsonlite") - what <- jsonlite::fromJSON(catfact_api)$fact - by <- "cat" - } - - who <- get_who(by, length = length) - - if (!is_null(fortune)) { - rlang::check_installed("fortunes") - what <- "fortune" - } - - if (what == "time") { - what <- as.character(Sys.time()) - } - - if (what == "fortune") { - rlang::check_installed("fortunes") - if (is_null(fortune)) { - fortune <- sample(1:360, 1) - } - what <- as.character(fortune(which = fortune, ...)) - what <- what[!are_na(what)] # remove missing pieces (e.g. "context") - what <- gsub("", "\n", paste(what, collapse = "\n ")) - } - - if (by == "hypnotoad" && what == "Hello world!") { - what <- "All Glory to the HYPNO TOAD!" - } - - if (what == "rms") { - rlang::check_installed("rmsfact") - what <- rmsfact::rmsfact() - } - - if (what %in% fillerama_what) { - abort("sorry, fillerama API is gone, sorry :(") - } +say <- say_think(thought_sym = "\\", say_or_think = "say") - what_bubbled <- bubble(x = what, width = width) - what_styled <- color_text(what_bubbled, what_color) - what_tail <- bubble_tail(who, thought_sym = thought_sym) - tail_styled <- color_text(what_tail, what_color) - who_styled <- color_text(who, by_color) - what_who <- paste(c(what_styled, tail_styled, who_styled), collapse = "\n") - - if (type == "warning") { - if (nchar(what_who) < 100) { - wl <- 100 - } else if (nchar(what_who) > 8170) { - wl <- 8170 - } else { - wl <- nchar(what_who) + 1 - } - warn_op <- options(warning.length = wl) - on.exit(options(warn_op)) - } - - switch(type, - message = message(what_who), - warning = warning(what_who), - print = cat(what_who), - string = what_who - ) -} +#' @export +#' @rdname say +think <- say_think(thought_sym = "o", say_or_think = "think") diff --git a/README.Rmd b/README.Rmd index dc4ce73..bf4b7bd 100644 --- a/README.Rmd +++ b/README.Rmd @@ -180,7 +180,7 @@ say(

-This doesn't preclude you from adding extra crayon colors to your `what` string directly. +This doesn't preclude you from adding extra crayon colors to your `what` string directly - but the results are not super pretty: ```{r eval=FALSE} @@ -190,7 +190,6 @@ say( ) ``` -

trilobite

@@ -257,6 +256,7 @@ say(by = "fish") ### R fortunes ```{r} +library(fortunes) say("fortune", "cat") ``` diff --git a/README.md b/README.md index 2ae20d9..7c20b45 100644 --- a/README.md +++ b/README.md @@ -132,11 +132,11 @@ sort(names(animals)) ``` r say("time") #> -#> +------------------------------+ -#> |2024-11-03 07:01:41.670953 | -#> +------------------------------+ -#> o -#> o +#> ---------------------------- +#> < 2024-12-04 06:18:44.375102 > +#> ---------------------------- +#> \ +#> \ #> #> ^__^ #> (oo)\ ________ @@ -149,12 +149,11 @@ say("time") ``` r say("ain't that some shit", "chicken") #> -#> +------------------------+ -#> |ain't that some shit | -#> +------------------------+ -#> o -#> o -#> +#> ---------------------- +#> < ain't that some shit > +#> ---------------------- +#> \ +#> \ #> _ #> _/ } #> `>' \ @@ -221,7 +220,7 @@ say(

-This doesn't preclude you from adding extra crayon colors to your `what` string directly. +This doesn't preclude you from adding extra crayon colors to your `what` string directly - but the results are not super pretty: @@ -232,7 +231,6 @@ say( ) ``` -

trilobite

@@ -243,11 +241,11 @@ say( ``` r say("hell no!") #> -#> +------------+ -#> |hell no! | -#> +------------+ -#> o -#> o +#> ---------- +#> < hell no! > +#> ---------- +#> \ +#> \ #> #> ^__^ #> (oo)\ ________ @@ -261,11 +259,11 @@ say("hell no!") ``` r say("hell no!", type = "warning") #> Warning in say("hell no!", type = "warning"): -#> +------------+ -#> |hell no! | -#> +------------+ -#> o -#> o +#> ---------- +#> < hell no! > +#> ---------- +#> \ +#> \ #> #> ^__^ #> (oo)\ ________ @@ -278,7 +276,7 @@ say("hell no!", type = "warning") ``` r say("hell no!", type = "string") -#> [1] "\n+------------+\n|hell no! |\n+------------+\n o\n o\n\n ^__^ \n (oo)\\ ________ \n (__)\\ )\\ /\\ \n ||------w|\n || ||" +#> [1] "\n ---------- \n< hell no! >\n ---------- \n \\\n \\\n\n ^__^ \n (oo)\\ ________ \n (__)\\ )\\ /\\ \n ||------w|\n || ||" ``` @@ -290,11 +288,14 @@ From the catfacts API at ``` r say("catfact", "cat") #> -#> +-----------------------------------------------+ -#> |The cat's tail is used to maintain balance. | -#> +-----------------------------------------------+ -#> o -#> o +#> ------------------------------------------------------- +#> / The lightest cat on record is a blue point Himalayan \ +#> | called Tinker Toy, who weighed 1 pound, 6 ounces (616 | +#> | g). Tinker Toy was 2.75 inches (7 cm) tall and 7.5 | +#> \ inches (19 cm) long. / +#> ------------------------------------------------------- +#> \ +#> \ #> #> |\___/| #> ==) ^Y^ (== @@ -325,11 +326,11 @@ say("it's caturday", "longcat") #> [BoingBoing] #> ' #> -#> +-----------------+ -#> |it's caturday | -#> +-----------------+ -#> o -#> o +#> --------------- +#> < it's caturday > +#> --------------- +#> \ +#> \ #> #> .ハ,,ハ #> ( ゚ω゚) @@ -346,11 +347,11 @@ say("it's caturday", "longcat") ``` r say("NO!", by = "grumpycat") #> -#> +-------+ -#> |NO! | -#> +-------+ -#> o -#> o +#> ----- +#> < NO! > +#> ----- +#> \ +#> \ #> #> ハ _ ハ #> ಠ X ಠ @@ -361,11 +362,11 @@ say("NO!", by = "grumpycat") ``` r say("WOKE UP TODAY, IT WAS TERRIBLE", by = "grumpycat") #> -#> +----------------------------------+ -#> |WOKE UP TODAY, IT WAS TERRIBLE | -#> +----------------------------------+ -#> o -#> o +#> -------------------------------- +#> < WOKE UP TODAY, IT WAS TERRIBLE > +#> -------------------------------- +#> \ +#> \ #> #> ハ _ ハ #> ಠ X ಠ @@ -376,11 +377,11 @@ say("WOKE UP TODAY, IT WAS TERRIBLE", by = "grumpycat") ``` r say("I HAD FUN ONCE, IT WAS AWFUL", by = "grumpycat") #> -#> +--------------------------------+ -#> |I HAD FUN ONCE, IT WAS AWFUL | -#> +--------------------------------+ -#> o -#> o +#> ------------------------------ +#> < I HAD FUN ONCE, IT WAS AWFUL > +#> ------------------------------ +#> \ +#> \ #> #> ハ _ ハ #> ಠ X ಠ @@ -393,11 +394,11 @@ say("I HAD FUN ONCE, IT WAS AWFUL", by = "grumpycat") ``` r say(by = "signbunny") #> -#> +----------------+ -#> |Hello world! | -#> +----------------+ -#> o -#> o +#> -------------- +#> < Hello world! > +#> -------------- +#> \ +#> \ #> #> (\__/) || #> (•ㅅ•) || @@ -412,11 +413,11 @@ say(by = "signbunny") ``` r say(by = "fish") #> -#> +----------------+ -#> |Hello world! | -#> +----------------+ -#> o -#> o +#> -------------- +#> < Hello world! > +#> -------------- +#> \ +#> \ #> #> ><((((º> ><((((º> ><((((º> ><((((º> ><((((º> #> Kiyoko Gotanda @@ -427,17 +428,27 @@ say(by = "fish") ``` r +library(fortunes) say("fortune", "cat") #> -#> +--------------------------------------------------------------+ -#> |I thought RStudio was amazing, but RStudio with knitr is | -#> |approximately `formatC(round(runif(1, 1e8, 1e9)), | -#> |digits=10, big.mark=',')` times better than RStudio alone! | -#> |@Geneorama comment on RStudio's new web publishing service | -#> |RStudio blog June 2012 | -#> +--------------------------------------------------------------+ -#> o -#> o +#> -------------------------------------------------------- +#> / Fabio Mulazzani: I need to obtain all the \ +#> | 9.somethingExp157 permutations that can be given from | +#> | the numbers from 1 to 100. Ted Harding: To an adequate | +#> | approximation there are 10^158 of them. Simply to | +#> | obtain them all (at a rate of 10^10 per second, which | +#> | is faster than the CPU frequency of most desktop | +#> | computers) would take 10^148 seconds, or slightly | +#> | longer than 3*(10^140) years. Current estimates of the | +#> | age of the Universe are of the order of 1.5*(10^10) | +#> | years, so the Universe will have to last about | +#> | 2*(10^130) times as long as it has already existed, | +#> | before the task could be finished. So: why do you want | +#> | to do this? Fabio Mulazzani and Ted Harding R-help | +#> \ November 2008 / +#> -------------------------------------------------------- +#> \ +#> \ #> #> |\___/| #> ==) ^Y^ (== @@ -458,15 +469,15 @@ You can also pick a particular fortune by number or regex search - if the `fortu ``` r say(fortune = 100) #> -#> +---------------------------------------------------------------+ -#> |I'm not sure I'd trust any computer recommendation from | -#> |1976, no matter how famous the authors are. Peter Dalgaard | -#> |after Samuel Edward Kemp cited a recommendation about | -#> |nonlinear least squares computer programs from | -#> |'Box-Jenkins, 1976' R-help January 2005 | -#> +---------------------------------------------------------------+ -#> o -#> o +#> --------------------------------------------------------- +#> / I'm not sure I'd trust any computer recommendation from \ +#> | 1976, no matter how famous the authors are. Peter | +#> | Dalgaard after Samuel Edward Kemp cited a | +#> | recommendation about nonlinear least squares computer | +#> \ programs from 'Box-Jenkins, 1976' R-help January 2005 / +#> --------------------------------------------------------- +#> \ +#> \ #> #> ^__^ #> (oo)\ ________ @@ -479,19 +490,20 @@ say(fortune = 100) ``` r say(fortune = "whatever") #> -#> +---------------------------------------------------------------+ -#> |Tom Backer Johnsen: I have just started looking at R, and | -#> |are getting more and more irritated at myself for not | -#> |having done that before. However, one of the things I have | -#> |not found in the documentation is some way of preparing | -#> |output from R for convenient formatting into something like | -#> |MS Word. Barry Rowlingson: Well whatever you do, don't | -#> |start looking at LaTeX, because that will get you even more | -#> |irritated at yourself for not having done it before. Tom | -#> |Backer Johnsen and Barry Rowlingson R-help February 2006 | -#> +---------------------------------------------------------------+ -#> o -#> o +#> --------------------------------------------------------- +#> / Tom Backer Johnsen: I have just started looking at R, \ +#> | and are getting more and more irritated at myself for | +#> | not having done that before. However, one of the things | +#> | I have not found in the documentation is some way of | +#> | preparing output from R for convenient formatting into | +#> | something like MS Word. Barry Rowlingson: Well whatever | +#> | you do, don't start looking at LaTeX, because that will | +#> | get you even more irritated at yourself for not having | +#> | done it before. Tom Backer Johnsen and Barry | +#> \ Rowlingson R-help February 2006 / +#> --------------------------------------------------------- +#> \ +#> \ #> #> ^__^ #> (oo)\ ________ @@ -509,11 +521,11 @@ say("Hi there :)", by = "trilobite") ```` #> -#> +---------------+ -#> |Hi there :) | -#> +---------------+ -#> o -#> o +#> ------------- +#> < Hi there :) > +#> ------------- +#> \ +#> \ #> #> _____ #> .'` ,-. `'. @@ -533,11 +545,11 @@ say("Hi there :)", by = "trilobite") ``` r say("Q: What do you call a solitary shark\nA: A lone shark", by = "shark") #> -#> +--------------------------------------------------------+ -#> |Q: What do you call a solitary shark A: A lone shark | -#> +--------------------------------------------------------+ -#> o -#> o +#> ------------------------------------------------------ +#> < Q: What do you call a solitary shark A: A lone shark > +#> ------------------------------------------------------ +#> \ +#> \ #> #> /""-._ #> . '-, @@ -575,11 +587,11 @@ say("Q: What do you call a single buffalo?\nA: A buffalonely", by = "buffalo") ````` #> -#> +----------------------------------------------------------+ -#> |Q: What do you call a single buffalo? A: A buffalonely | -#> +----------------------------------------------------------+ -#> o -#> o +#> -------------------------------------------------------- +#> < Q: What do you call a single buffalo? A: A buffalonely > +#> -------------------------------------------------------- +#> \ +#> \ #> #> _.-````'-,_ #> _,.,_ ,-'` `'-.,_ @@ -602,17 +614,17 @@ say("Q: What do you call a single buffalo?\nA: A buffalonely", by = "buffalo") ``` r say(fortune = 59, by = "clippy") #> -#> +-------------------------------------------------------------+ -#> |Let's not kid ourselves: the most widely used piece of | -#> |software for statistics is Excel. Brian D. Ripley | -#> |'Statistical Methods Need Software: A View of Statistical | -#> |Computing' Opening lecture RSS 2002, Plymouth September | -#> |2002 | -#> +-------------------------------------------------------------+ -#> o -#> o -#> -#> __ +#> -------------------------------------------------------- +#> / Let's not kid ourselves: the most widely used piece of \ +#> | software for statistics is Excel. Brian D. Ripley | +#> | 'Statistical Methods Need Software: A View of | +#> | Statistical Computing' Opening lecture RSS 2002, | +#> \ Plymouth September 2002 / +#> -------------------------------------------------------- +#> \ +#> \ +#> +#> _ #> / \ #> | | #> @ @ @@ -635,11 +647,11 @@ say("fortune", by = "yoda") ``` r say("hi, i'm a bat", by = "bat") #> -#> +-----------------+ -#> |hi, i'm a bat | -#> +-----------------+ -#> o -#> o +#> --------------- +#> < hi, i'm a bat > +#> --------------- +#> \ +#> \ #> #> __.--'\ \.__./ /'--.__ #> _.-' '.__.' '.__.' '-._ @@ -661,17 +673,15 @@ See also `bat2` ``` r say("fortune", by = "monkey") #> -#> +--------------------------------------------------------------+ -#> |That's a casual model, not a causal model - you can tell | -#> |the difference by looking for the word "excel". Hadley | -#> |Wickham commenting on an Excel chart showing student's SAT | -#> |score increases with family income, without considering | -#> |further covariates http://twitter.com/#!/hadleywickham | -#> |February 2012 | -#> +--------------------------------------------------------------+ -#> o -#> o -#> +#> ---------------------------------------------------- +#> / The good way to do it is to include the following \ +#> | comment at the beginning: # This is a holy Script, | +#> | please edit it not Kenn Konstabel on "... how to | +#> | protect R Script files from inadvertent editing by | +#> \ users." R-help April 2011 / +#> ---------------------------------------------------- +#> \ +#> \ #> #> .="=. #> _/.-.-.\_ _ @@ -693,17 +703,16 @@ say("fortune", by = "monkey") ``` r say("fortune", by = "daemon") #> -#> +------------------------------------------------------------+ -#> |I want a budget. Peter Dalgaard in a talk about Tcl/Tk, | -#> |meaning to say 'I want a button widget' gR 2003, Aalborg | -#> |September 2003 | -#> +------------------------------------------------------------+ -#> o -#> o -#> +#> --------------------------------------------------------- +#> / Soon, they'll be speaking R on the subway. Michael \ +#> | Rennie giving 'Kudos to the R support team' R-help July | +#> \ 2004 / +#> --------------------------------------------------------- +#> \ +#> \ #> , , -#> /( )` -#> \ \___ / | +#> /( )` +#> \ \___ / | #> /- _ `-/ ' #> (/\/ \ \ /\ #> / / | ` @@ -728,13 +737,13 @@ say("fortune", by = "daemon") ``` r say("je ne regrette rien", by = "egret") #> -#> +-----------------------+ -#> |je ne regrette rien | -#> +-----------------------+ -#> o -#> o +#> --------------------- +#> < je ne regrette rien > +#> --------------------- +#> \ +#> \ #> -#> \ _, +#> _, #> -==<' ` #> ) / #> / (_. @@ -797,11 +806,11 @@ endless_horse() library("magrittr") "I HAD FUN ONCE, IT WAS AWFUL" %>% say("grumpycat") #> -#> +--------------------------------+ -#> |I HAD FUN ONCE, IT WAS AWFUL | -#> +--------------------------------+ -#> o -#> o +#> ------------------------------ +#> < I HAD FUN ONCE, IT WAS AWFUL > +#> ------------------------------ +#> \ +#> \ #> #> ハ _ ハ #> ಠ X ಠ @@ -815,8 +824,8 @@ Okay, hold your endless horses. Just use the exported vector `animals`, and you ``` r animals["clippy"] -#> clippy -#> "\n__\n / \\\n | |\n @ @\n || ||\n || ||\n |\\_/|\n \\___/ GB\n" +#> clippy +#> "\n _\n / \\\n | |\n @ @\n || ||\n || ||\n |\\_/|\n \\___/ GB\n" ``` ## Meta diff --git a/man/bubble.Rd b/man/bubble_say.Rd similarity index 50% rename from man/bubble.Rd rename to man/bubble_say.Rd index ca0c8be..5574bd3 100644 --- a/man/bubble.Rd +++ b/man/bubble_say.Rd @@ -1,10 +1,13 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/bubble.R -\name{bubble} -\alias{bubble} +\name{bubble_say} +\alias{bubble_say} +\alias{bubble_think} \title{Thought/speech bubble/balloon} \usage{ -bubble(x, width = 60) +bubble_say(x, width = 60) + +bubble_think(x, width = 60) } \arguments{ \item{x}{(character) a character vector} @@ -17,6 +20,12 @@ character vector of length greater than the input \code{x} \description{ Thought/speech bubble/balloon } +\details{ +\code{bubble_say} gives the traditional bubble that you get when +you run \code{cowsay} on the command line, with carrots or slashes for the +sides, while \code{bubble_think} gives a slightly different bubble with +parens for the sides +} \note{ modified from \url{https://github.com/schochastics/startifyR} } @@ -24,12 +33,16 @@ modified from \url{https://github.com/schochastics/startifyR} \dontshow{if (rlang::is_installed("fortunes")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} library(fortunes) quote <- as.character(fortune()) -bubble(x = quote) +bubble_say(x = quote) +cat(bubble_say(paste(quote, collapse = " ")), sep = "\n") +ch <- animals[["chicken"]] +z <- paste(c(bubble_say(quote), bubble_tail(ch, "\\\\"), ch), collapse = "\n") +cat(z) +\dontshow{\}) # examplesIf} +\dontshow{if (rlang::is_installed("fortunes") && interactive()) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} text_color <- sample(grDevices::colors(), 1) text_style <- crayon::make_style(text_color) -text_style(bubble(quote)) - -cat(bubble(paste(quote, collapse = " ")), sep = "\n") +text_style(bubble_say(quote)) \dontshow{\}) # examplesIf} } diff --git a/man/bubble_tail.Rd b/man/bubble_tail.Rd index 3595ce7..ca49214 100644 --- a/man/bubble_tail.Rd +++ b/man/bubble_tail.Rd @@ -23,8 +23,13 @@ to determine how much whitespace padding to add to the left of \description{ Make the tail part of a thought bubble } +\details{ +\code{bubble_tail} uses the animal as input so that the tail is put +close to the top of the animal, whereas \code{bubble_tail2} just puts the tail +about a 1/3 of the way from the left most character given the max +character length +} \examples{ -\dontshow{if (interactive()) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} bubble_tail(animals[["chicken"]]) cat(bubble_tail(animals[["chicken"]]), sep = "\n") cat(bubble_tail(animals[["chicken"]]), sep = "\n") @@ -34,5 +39,4 @@ bubble_tail2(59) cat(bubble_tail2(59), sep = "\n") cat(bubble_tail2(11), sep = "\n") cat(bubble_tail2(11, "\%"), sep = "\n") -\dontshow{\}) # examplesIf} } diff --git a/man/figures/ghost.png b/man/figures/ghost.png index 5697a91..c97a738 100644 Binary files a/man/figures/ghost.png and b/man/figures/ghost.png differ diff --git a/man/figures/irish_buffalo.jpg b/man/figures/irish_buffalo.jpg deleted file mode 100644 index 7ea7373..0000000 Binary files a/man/figures/irish_buffalo.jpg and /dev/null differ diff --git a/man/figures/owl.png b/man/figures/owl.png index 45ab3aa..965d5a8 100644 Binary files a/man/figures/owl.png and b/man/figures/owl.png differ diff --git a/man/figures/rms.png b/man/figures/rms.png index dd69b41..67e0f3d 100644 Binary files a/man/figures/rms.png and b/man/figures/rms.png differ diff --git a/man/figures/trilobite.png b/man/figures/trilobite.png index 216dbde..34c76ce 100644 Binary files a/man/figures/trilobite.png and b/man/figures/trilobite.png differ diff --git a/man/say.Rd b/man/say.Rd index 101fb39..a2a7652 100644 --- a/man/say.Rd +++ b/man/say.Rd @@ -2,6 +2,7 @@ % Please edit documentation in R/say.R \name{say} \alias{say} +\alias{think} \title{Sling messages and warnings with flair} \usage{ say( @@ -12,7 +13,18 @@ say( by_color = what_color, length = 18, fortune = NULL, - thought_sym = "o", + width = 60, + ... +) + +think( + what = "Hello world!", + by = "cow", + type = NULL, + what_color = NULL, + by_color = what_color, + length = 18, + fortune = NULL, width = 60, ... ) @@ -62,9 +74,6 @@ string which is used as a pattern passed to \code{\link[=grep]{grep()}} (and a r selected upton multiple matches). Passed on to the \code{which} parameter of \code{fortunes::fortune}} -\item{thought_sym}{(character) scalar character to use for the -speech bubble tail (see \url{https://en.wikipedia.org/wiki/Speech_balloon})} - \item{width}{(integer/numeric) width of each line. default: 60} \item{...}{Further args passed on to \code{fortunes::fortune()}} diff --git a/man/say_think.Rd b/man/say_think.Rd new file mode 100644 index 0000000..51907ae --- /dev/null +++ b/man/say_think.Rd @@ -0,0 +1,19 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/say.R +\name{say_think} +\alias{say_think} +\title{say/think factory} +\usage{ +say_think(thought_sym, say_or_think) +} +\arguments{ +\item{thought_sym}{(character) scalar character to use for the +speech bubble tail (see \url{https://en.wikipedia.org/wiki/Speech_balloon}). +default: "o"} + +\item{say_or_think}{(character)} +} +\description{ +say/think factory +} +\keyword{internal} diff --git a/vignettes/cowsay.Rmd b/vignettes/cowsay.Rmd index fd092dd..e04a3d8 100644 --- a/vignettes/cowsay.Rmd +++ b/vignettes/cowsay.Rmd @@ -103,4 +103,3 @@ String ```{r} say("hello world", by = "cow", type = "string") ``` -