360SDN.COM

R Fortunes

来源:  2017-07-28 17:04:48    评论:0点击:

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

fortune() # a random one
fortune("Ripley") # a random one from those with 'Ripley'
fortune(author = "Ripley") # a random one from those by 'Ripley'
fortune(17)

fortune("parse", showMatches = TRUE) # -> shows at least 5 matches
fortune("parse.*answer") # nothing found but...
fortune("parse.*answer", fixed = FALSE) # ...this works


## The first three "all together"   ('setNames()' requires at least R 3.0.0):
lapply(setNames(, c(38, 106, 129)), fortune)

为您推荐

友情链接 |九搜汽车网 |手机ok生活信息网|ok生活信息网|ok微生活
 Powered by www.360SDN.COM   京ICP备11022651号-4 © 2012-2016 版权