Type: | Package |
Title: | Get Facts and Data from Wikipedia and Wikidata |
Version: | 0.4.2 |
Description: | Query Wikidata and get facts from current and historic Wikipedia main pages. |
License: | CC0 |
Encoding: | UTF-8 |
Imports: | magrittr, rvest, utils, xml2 |
RoxygenNote: | 7.1.1 |
Suggests: | covr, testthat |
NeedsCompilation: | no |
Packaged: | 2021-04-29 14:11:51 UTC; rstudio |
Author: | Keith McNulty |
Maintainer: | Keith McNulty <keith.mcnulty@gmail.com> |
Repository: | CRAN |
Date/Publication: | 2021-04-29 14:20:02 UTC |
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()
Display results of a Wikipedia search in the browser
Description
'wiki_search()' displays the results of a Wikipedia search in the browser.
Usage
wiki_search(term = NULL, browser = getOption("browser"))
Arguments
term |
A non-empty character string giving the name of the term to be searched |
browser |
A non-empty character string passed to [browseURL()] to determine the browser used. |
Value
A display of the results of the search in the browser.
Examples
wiki_search('R (programming language)')