jayqi / spongebob

SPoNgeBOb-CAse cONveRSioN ToOLs
https://jayqi.github.io/spongebob/
27 stars 3 forks source link

Make a function to wrap fortunes #10

Closed jayqi closed 5 years ago

jayqi commented 5 years ago

The fortunes::fortune() function unfortunately returns an object with a complex interface:

str(fortunes::fortune())
#> List of 5
#>  $ quote  : chr "It's not meant for sampling weights. It's meant for precision weights. How best to include sampling weights in "| __truncated__
#>  $ author : chr "Thomas Lumley"
#>  $ context: chr "in reponse to a question about specifying sampling weights in lme4"
#>  $ source : chr "R-help"
#>  $ date   : chr "January 2012"
#>  - attr(*, "row.names")= int 307
#>  - attr(*, "class")= chr "fortune"

Created on 2019-01-31 by the reprex package (v0.2.1)

The documentation also isn't great, which makes it kludgy to use if you don't remember its class variables. We could make a function like spongebob_fortune that does something like:

f <- fortunes::fortune()
paste0(f$quote, "  -", f$author)

Other packages like praise::praise() don't have this problem because they simply return a character string, so we can just provide simple examples in a vignette, per #4.

jayqi commented 5 years ago

This was resolved in #18. The new S3 class method tospongebob.fortune handles returning a valid fortune object with its text converted. This means we can still take advantage of other methods for fortune objects, like print.fortune.