Package 'wikifacts'

Title: Get Facts and Data from Wikipedia and Wikidata
Description: Query Wikidata and get facts from current and historic Wikipedia main pages.
Authors: Keith McNulty [aut, cre] , Petr Kajzar [ctb]
Maintainer: Keith McNulty <[email protected]>
License: CC0
Version: 0.4.2.9999
Built: 2025-03-11 02:44:09 UTC
Source: https://github.com/keithmcnulty/wikifacts

Help Index


Define a term from Wikipedia

Description

'wiki_define()' displays plaintext extract(s) of the given term(s) from ' the Wikipedia article(s).

Usage

wiki_define(term = NULL, sentences = 5L)

Arguments

term

A non-empty character string or vector giving the name(s) of the term to be searched

sentences

An integer (or whole number) giving the number of sentences to return

Value

An extract from the Wikipedia article

Examples

wiki_define('R (programming language)')

animals <- data.frame(name = c("dog", "cat"))
animals$definition <- wiki_define(animals$name, sentences = 1)
print(animals)

Generate 'did you know' facts from the Wikipedia main page on a specified date.

Description

‘wiki_didyouknow()' generates ’did you know' facts from the Wikipedia main page on a specified date.

Usage

wiki_didyouknow(
  n_facts = 1L,
  date = sample(seq(as.Date("2015-01-01"), Sys.Date() - 1, by = "day"), 1),
  bare_fact = FALSE
)

Arguments

n_facts

An integer determining the number of facts that will be generated, up to a limit of the maximum facts for the date specified.

date

A date string of the form YYYY-MM-DD. Default value is a random date since 1 January 2015.

bare_fact

Logical. Determining whether the fact should be quoted as is or surrounded by a preamble and courtesy statement.

Value

A vector of strings with random 'did you know' facts from Wikipedia's main page if it exists for the date specified - otherwise "I got nothin'"

Examples

wiki_didyouknow(n_facts = 2, date = '2020-05-02')

Generate news items from the Wikipedia main page on a specified date.

Description

'wiki_inthenews()' generates news items from the Wikipedia main page on a specified date.

Usage

wiki_inthenews(
  n_facts = 1L,
  date = sample(seq(as.Date("2015-01-01"), Sys.Date() - 1, by = "day"), 1),
  bare_fact = FALSE
)

Arguments

n_facts

An integer determining the number of facts that will be generated, up to a limit of the maximum facts for the date specified.

date

A date string of the form YYYY-MM-DD. Default value is a random date since 1 January 2015.

bare_fact

Logical. Determining whether the fact should be quoted as is or surrounded by a preamble and courtesy statement.

Value

A vector of strings with random 'in the news' items from Wikipedia's main page, if it exists for the date specified - otherwise "I got nothin'"

Examples

wiki_inthenews(n_facts = 1, date = '2020-05-02')

Generate 'on this day' facts from the Wikipedia main page on a specified date.

Description

‘wiki_onthisday()' generates ’on this day' facts from the Wikipedia main page on a specified date.

Usage

wiki_onthisday(
  n_facts = 1L,
  date = sample(seq(as.Date("2015-01-01"), Sys.Date() - 1, by = "day"), 1),
  bare_fact = FALSE
)

Arguments

n_facts

An integer determining the number of facts that will be generated, up to a limit of the maximum facts for the date specified.

date

A date string of the form YYYY-MM-DD. Default value is a random date since 1 January 2015.

bare_fact

Logical. Determining whether the fact should be quoted as is or surrounded by a preamble and courtesy statement.

Value

A vector of strings with random 'on this day' facts from Wikipedia's main page if it exists for the date specified - otherwise "I got nothin'"

Examples

wiki_onthisday(date = '2020-05-02')

Send queries to Wikidata and receive results as dataframe

Description

'wiki_query()' sends a SPARQL query to Wikidata and collects the results in a dataframe

Usage

wiki_query(qry)

Arguments

qry

A character string representing a SPARQL query to be sent to Wikidata

Value

A dataframe of results

Examples

# List five diseases
query <- 'SELECT ?itemLabel WHERE {
  ?item wdt:P31 wd:Q12136. #instance of disease
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
LIMIT 5'
wiki_query(query)

Generate random facts from historic Wikipedia main pages

Description

'wiki_randomfact()' generates random facts from Wikipedia main pages after 1 January 2015.

Usage

wiki_randomfact(
  n_facts = 1L,
  fact = c("any", "didyouknow", "onthisday", "inthenews"),
  bare_fact = FALSE,
  repeats = TRUE
)

Arguments

n_facts

An integer determining the number of facts that will be generated.

fact

String to determine the type of fact to be randomly generated - "any" will generate a random selection.

bare_fact

Logical. Determining whether the fact should be quoted as is or surrounded by a preamble and courtesy statement.

repeats

Logical. Determining if repeat facts should be permitted. If FALSE the number of facts may be less than requested.

Value

A vector of strings with random items from Wikipedia's main page - otherwise "I got nothin'"

Examples

wiki_randomfact()