Open In App

wikifacts package in R

Last Updated : 18 Mar, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

In this article, we will be working with wikifacts package of R Programming Language. We will have a look at several functions of wikifacts package to scrap data like events, facts, and news.

Installation:

To install this package type the below command in the terminal.

install.packages(“wikifacts”)

wikifacts is an R package that can be used to scrape data from Wikipedia and wiki data.

Getting Definition of words

wiki_define(“word”) function: Returns the definition of the words from Wikipedia and wiki data.

Syntax:

wiki_define("word") 

R




# installing packages
install.packages("wikifacts")
  
# importing packages
library(wikifacts)
  
# gets definition of the word
cat(wiki_define("python"))


Output:

Python may refer to:

Pythonidae, a family of nonvenomous snakes found in Africa, Asia, and Australia

Python (genus), a genus of nonvenomous Pythonidae found in Africa and Asia

== Computing ==

Python (programming language)

Python, a native code compiler for CMU Common Lisp

Python, the internal project name for the PERQ 3 computer workstation

…..

Get news:

wiki_inthenews() function: Returns the random trending news.

Syntax:

wiki_inthenews()

Example:

R




# installing packages
install.packages("wikifacts")
  
# importing packages
library(wikifacts)
  
# returns the random news
cat(wiki_inthenews())


Output:

Here’s some news from 07 October 2017. In Saudi Arabia, a decree by King Salman effectively removes a longstanding ban on women driving in the country. (Courtesy of Wikipedia)

Get random facts:

wiki_didyouknow() function: returns the random fact.

Syntax:

wiki_didyouknow()

wiki_onthisday() function: returns random facts from the past of the current date.

Syntax:

wiki_onthisday()

R




# installing packages
install.packages("wikifacts")
  
# importing packages
library(wikifacts)
  
# Gets random fact
cat(wiki_didyouknow())
  
# Get random fact from the past of 
# current date
cat(wiki_onthisday())


Output:

Did you know that the population of Kunság (banner pictured) was “almost entirely wiped out” during the Ottoman occupation, before recovering through re-colonization? (Courtesy of Wikipedia)

Did you know that on March 9 in 1932 – Éamon de Valera (pictured), one of the dominant political figures in twentieth-century Ireland, became President of the Executive Council of the Irish Free State. (Courtesy of Wikipedia)



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads