Skip to content

Commit

Permalink
make fortunes be Suggests pkg instead of Imports
Browse files Browse the repository at this point in the history
  • Loading branch information
sckott committed Nov 4, 2024
1 parent 3218def commit 2813228
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 58 deletions.
5 changes: 2 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,12 @@ Language: en-US
VignetteBuilder: knitr
Imports:
crayon,
fortunes,
rlang
Suggests:
curl,
fortunes,
rmsfact,
jsonlite,
knitr,
rmarkdown,
rmsfact,
testthat
RoxygenNote: 7.3.2
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ test:
${RSCRIPT} -e "devtools::test()"

check: build
_R_CHECK_SYSTEM_CLOCK=0 _R_CHECK_CRAN_INCOMING_=FALSE R CMD CHECK --as-cran --no-manual `ls -1tr ${PACKAGE}*gz | tail -n1`
_R_CHECK_SYSTEM_CLOCK=FALSE _R_CHECK_CRAN_INCOMING_=FALSE R CMD CHECK --as-cran --no-manual `ls -1tr ${PACKAGE}*gz | tail -n1`
@rm -f `ls -1tr ${PACKAGE}*gz | tail -n1`
@rm -rf ${PACKAGE}.Rcheck

Expand Down
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ export(animals)
export(bubble)
export(endless_horse)
export(say)
importFrom(fortunes,fortune)
importFrom(rlang,abort)
importFrom(rlang,are_na)
importFrom(rlang,arg_match)
Expand Down
2 changes: 1 addition & 1 deletion R/bubble.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#' default: "o"
#' @return character vector of length greater than the input `x`
#' @note modified from <https://github.com/schochastics/startifyR>
#' @examples
#' @examplesIf rlang::is_installed("fortunes")
#' library(fortunes)
#' quote <- as.character(fortune())
#' bubble(x = quote)
Expand Down
1 change: 0 additions & 1 deletion R/cowsay-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"_PACKAGE"

## usethis namespace: start
#' @importFrom fortunes fortune
#' @importFrom rlang has_length is_null arg_match abort inform
#' is_character are_na set_names
## usethis namespace: end
Expand Down
68 changes: 41 additions & 27 deletions R/say.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@
#' to color `who`. Use "rainbow" for
#' `c("red", "orange", "yellow", "green", "blue", "purple")`
#' @param length (integer) Length of longcat. Ignored if other animals used.
#' @param fortune An integer specifying the row number of fortunes.data.
#' Alternatively which can be a character and grep is used to try to find a
#' suitable row.
#' @param fortune An integer (or number that can be coerced
#' to integer) specifying a fortune from the `fortunes` package - OR a
#' 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 <https://en.wikipedia.org/wiki/Speech_balloon>)
#' @param width (integer/numeric) width of each line. default: 60
#' @param ... Further args passed on to [fortunes::fortune()]
#' @param ... Further args passed on to `fortunes::fortune()`
#'
#' @section what:
#' You can put in any phrase you like to the `what` parameter, OR you
Expand Down Expand Up @@ -79,32 +81,12 @@
#' say("icanhazpdf?", "cat")
#' say("boo!", "pumpkin")
#' say("hot diggity", "frog")
#' say("fortune", "spider")
#' say("fortune", "facecat")
#' say("fortune", "behindcat")
#' say("fortune", "smallcat")
#' say("fortune", "monkey")
#' say("fortune", "egret")
#' say("rms", "rms")
#'
#' # Vary type of output, default calls message()
#' say("hell no!")
#' say("hell no!", type = "warning")
#' say("hell no!", type = "string")
#'
#' # Using fortunes
#' say(what = "fortune")
#' ## you don't have to pass anything to the `what` parameter if `fortune` is
#' ## not null
#' say(fortune = 10)
#' say(fortune = 100)
#' say(fortune = "whatever")
#' say(fortune = 7)
#' say(fortune = 45)
#'
#' # Using catfacts
#' # say("catfact", "cat")
#'
#'
#' # The hypnotoad
#' say(by = "hypnotoad")
#'
Expand All @@ -117,8 +99,34 @@
#' # Buffalo
#' say("Q: What do you call a single buffalo?\nA: A buffalonely", by = "buffalo")
#'
#' @examplesIf rlang::is_installed("fortunes")
#' # Using fortunes
#' library(fortunes)
#' say(what = "fortune")
#' ## you don't have to pass anything to the `what` parameter if `fortune` is
#' ## not null
#' say("fortune", "spider")
#' say("fortune", "facecat")
#' say("fortune", "behindcat")
#' say("fortune", "smallcat")
#' say("fortune", "monkey")
#' say("fortune", "egret")
#' say(fortune = 10)
#' say(fortune = 100)
#' say(fortune = "whatever")
#' say(fortune = 7)
#' say(fortune = 45)
#' # Clippy
#' say(fortune = 59, by = "clippy")
#'
#' @examplesIf rlang::is_installed("rmsfact")
#' library(rmsfact)
#' say("rms", "rms")
#'
#' @examplesIf rlang::is_installed("jsonlite")
#' # Using the catfacts API
#' library(jsonlite)
#' say("catfact", "cat")
say <- function(
what = "Hello world!", by = "cow", type = NULL,
what_color = NULL, by_color = NULL, length = 18, fortune = NULL,
Expand Down Expand Up @@ -156,14 +164,20 @@ say <- function(

who <- get_who(by, length = length)

if (!is_null(fortune)) what <- "fortune"
if (!is_null(fortune)) {
rlang::check_installed("fortunes")
what <- "fortune"
}

if (what == "time") {
what <- as.character(Sys.time())
}

if (what == "fortune") {
if (is_null(fortune)) fortune <- sample(1:360, 1)
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("<x>", "\n", paste(what, collapse = "\n "))
Expand Down
2 changes: 2 additions & 0 deletions man/bubble.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

57 changes: 33 additions & 24 deletions man/say.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2813228

Please sign in to comment.