knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%" )
A deeply unserious package for generating random text that mimics a given input text using Markov chains.
You can install the development version of markovtext from GitHub with:
# install.packages("devtools") devtools::install_github("chris31415926535/markovtext")
The package has two main functions: markovtext::get_word_freqs()
generates a word-frequency table, and markovtext::generate_text()
uses that table to generate random text. It also includes a few sample word-frequency tables to get you started.
This package truly has something for everyone.
Perhaps you are a Doug Ford superfan, and your only wish in life is for a never-ending source of wisdom from Ontario's 26th Premier. Today is your lucky day, for nirvana is only one function call away:
dougford_text <- markovtext::generate_text(markovtext::wordfreqs_dougford_3grams, word_length = 100)
dougford_text
knitr::kable(dougford_text, col.names = "")
Or perhaps you're a beleaguered parent facing a three-year-old with an insatiable demand for Dr. Seuss bedtime stories. Again, I've got you covered:
seuss_text <- markovtext::generate_text(markovtext::wordfreqs_catinthehat_3grams, word_length = 100)
seuss_text
knitr::kable(seuss_text, col.names = "")
To create a word-frequency table, you can supply a character vector or a data.frame with a column named "text."
Here we'll build our table based on this famous aphorism from the philosopher James Robert Brown:
library(markovtext) text <- "I can do wheelin', I can do dealin', But I don't do no damn squealin'. I can dig rappin', I'm ready! I can dig scrappin'. But I can't dig that backstabbin'." wordfreqs <- markovtext::get_word_freqs(text, n_grams = 3)
Generating text is a simple call to generate_text()
.
new_text <- markovtext::generate_text(wordfreqs, word_length = 50)
new_text
knitr::kable(new_text, col.names = "")
Note that leading and trailing punctuation is trimmed.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.