R Fortunes

Description

Read and print R fortunes.

Usage

fortune(which = NULL, fortunes.data = NULL, fixed = TRUE,
        showMatches = FALSE, author = character(), ...)
## S3 method for class 'fortune'
print(x, width = NULL, ...)
read.fortunes(file = NULL)

Arguments

which 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.
fortunes.data data frame containing a fortune in each row. By default the fortune data from the fortunes package are used.
fixed logical passed to grep if which is a character, indicating if it should work (if TRUE, as by default) with a simple character string or (if FALSE) with regular expressions.
showMatches if which is character, a logical indicating if fortune() should print all the row numbers of fortunes.data which match the grep search.
author a character string to match (via grep) to the “authors” column of fortunes.data.
potential further arguments passed to grep.
x an object of class “fortune”, usually a single row from fortunes.data.
width integer specifying the character width. By default getOption(“width”) is used.
file a character string giving a fortune database in csv format (in UTF-8 encoding). By default all csv files in the data directory of the fortune package are used.

Value

fortune() returns an object of class “fortune” which is a row from a data frame of fortunes (like those read in from read.fortunes).

read.fortunes() returns a data frame of fortunes, each row contains:

quote the quote, main part of the fortune,
author the author of the quote,
context the context in which it was quoted (if available, otherwise NA),
source where it was quoted (if available, otherwise NA),
date when it was quoted (if available, otherwise NA).

Examples

library("fortunes")

fortune() # a random one

I prefer _Melodramatic Analysis_.
   -- Dirk Eddelbuettel (after Barry Rowlingson noticed 'Sentimental Analysis'
      as a misspelled 'Sentiment Analysis' on datascience.stackexchange.com)
      R chatroom on stackoverflow.com (April 2016)
fortune("Ripley") # a random one from those with 'Ripley'

I don't like to see the use of c() for its side effects. In this case Marc's
as.vector seems to me to be self-explanatory, and that is a virtue in
programming that is too often undervalued.
   -- Brian D. Ripley (on how to convert a matrix into a vector)
      R-help (March 2007)
fortune(author = "Ripley") # a random one from those by 'Ripley'

Lars Strand: Will R run under Windows Pocket PC?
Brian D. Ripley: We don't know! There are no binary versions of R for that
platform, but perhaps you could find a suitable compiler and manage to build
the sources.
Outside pure mathematics it is usually very hard to establish that something
cannot be done (and it can be very hard in pure mathematics, too).
   -- Lars Strand and Brian D. Ripley
      R-help (November 2004)

I plan to fix this - the report is just in case I forget or get hit by a bus.
   -- Ross Ihaka (reporting a bug in persp)
      R-help (October 2003)
fortune("parse", showMatches = TRUE) # -> shows at least 5 matches
Matching row numbers: 38, 106, 129, 181, 226 

If the answer is parse() you should usually rethink the question.
   -- Thomas Lumley
      R-help (February 2005)
fortune("parse.*answer") # nothing found but...
character(0)
fortune("parse.*answer", fixed = FALSE) # ...this works

Personally I have never regretted trying not to underestimate my own future
stupidity.
   -- Greg Snow (explaining why eval(parse(...)) is often suboptimal, answering
      a question triggered by the infamous fortune(106))
      R-help (January 2007)
## The first three "all together"   ('setNames()' requires at least R 3.0.0):
lapply(setNames(, c(38, 106, 129)), fortune)
$`38`

For almost 40 years SAS has been the primary tool for statisticians worldwide
and its easy-to-learn syntax, unsurpassed graphical system, powerful macro
language and recent graphical user interfaces have made SAS the number one
statistical software choice for both beginners and advanced users.
   -- Rolf Poalis, Biostatistics Denmark (announcement of the SAS to R parser
      sas2R)
      R-help (April 1, 2004)


$`106`

If the answer is parse() you should usually rethink the question.
   -- Thomas Lumley
      R-help (February 2005)


$`129`

See pages 45 and 46 of V&R's S PROGRAMMING for a definitive discussion of how
to do this.
(Confession: I treat anything that V&R say as definitive).
   -- Berton Gunter (in reply to the question how to parse a '...' function
      argument)
      R-help (June 2005)