Little useless-useful R functions – R Lorem Ipsum

Lorem Ipsum is simply dummy text of the printing and typesetting industry and extensively popularized in the past 60 years.

It’s main purpose it more than obvious, in addition the fact is that a reader is not distracted by readable content and is focusing on layout, outlook or design of a page (or specimen).

Idea is to have a Lorem Ipsum text for R community, randomly generated from all the functions available in base package. You might be thinking that users might get distracted by reading the content, but randomly selected names of the functions is as much readable as Lorem Ipsum text itself. But there is a twist. You might actually spot a function that you never heard of, when merely glancing over the text or when copy and pasting it in your design.

The code is consist of two steps. First one grabs all functions from base package:

function_list <- function(){
  lw <- builtins() #(internal = FALSE)
  lw2 <- help(package="base") 
  lw3 <- ls("package:base")
  lwA <- c(lw,lw2,lw3)
  lwA <- unique(lwA)
  lwA <- trimws(gsub("[[:punct:]]", " ", lwA))
  #ltrim / rtrim
  return(lwA)
  }

And the second part generates the length of the text based on the limitations of length and approximation.

RLoremIpsum <- function(text_length, approx=TRUE){
  lw <- function_list()
  LorIps <- ''
  while (nchar(LorIps) < text_length) {
    lw <- gsub("^ *|(?<= ) | *$", "", lw, perl = TRUE)
    new_w <-  sample(lw,1, replace=TRUE)
    LorIps <- paste(LorIps, new_w, sep = " ")
    if (approx==FALSE){
    LorIps <- substr(LorIps, 1, text_length)
    }
  }
 
  last_word <- tail(strsplit(LorIps ,split=" ")[[1]],1)
     if ((nchar(last_word) == 1) == TRUE) {
    LorIps <- substr(LorIps, 1, nchar(LorIps)-1) # replace last char with blank space
    }
   return(LorIps)
}

And simply generating the text:

# generated Lorem Ipsum with 1000 characters
RLoremIpsum(10000, approx=TRUE)

There is your random text filler. But this time, forget the Latin, hello R πŸ™‚

As always, code is available on Github.

Happy R-coding πŸ™‚

Tagged with: , , , , ,
Posted in Uncategorized
One comment on “Little useless-useful R functions – R Lorem Ipsum
  1. […] by data_admin [This article was first published on R – TomazTsql, and kindly contributed to R-bloggers]. (You can report issue about the content on this page […]

    Like

Leave a comment

Follow TomazTsql on WordPress.com
Programs I Use: SQL Search
Programs I Use: R Studio
Programs I Use: Plan Explorer
Rdeči Noski – Charity

Rdeči noski

100% of donations made here go to charity, no deductions, no fees. For CLOWNDOCTORS - encouraging more joy and happiness to children staying in hospitals (http://www.rednoses.eu/red-noses-organisations/slovenia/)

€2.00

Top SQL Server Bloggers 2018
TomazTsql

Tomaz doing BI and DEV with SQL Server and R, Python, Power BI, Azure and beyond

Discover WordPress

A daily selection of the best content published on WordPress, collected for you by humans who love to read.

Revolutions

Tomaz doing BI and DEV with SQL Server and R, Python, Power BI, Azure and beyond

tenbulls.co.uk

tenbulls.co.uk - attaining enlightenment with the Microsoft Data and Cloud Platforms with a sprinkling of Open Source and supporting technologies!

SQL DBA with A Beard

He's a SQL DBA and he has a beard

Reeves Smith's SQL & BI Blog

A blog about SQL Server and the Microsoft Business Intelligence stack with some random Non-Microsoft tools thrown in for good measure.

SQL Server

for Application Developers

Business Analytics 3.0

Data Driven Business Models

SQL Database Engine Blog

Tomaz doing BI and DEV with SQL Server and R, Python, Power BI, Azure and beyond

Search Msdn

Tomaz doing BI and DEV with SQL Server and R, Python, Power BI, Azure and beyond

R-bloggers

Tomaz doing BI and DEV with SQL Server and R, Python, Power BI, Azure and beyond

R-bloggers

R news and tutorials contributed by hundreds of R bloggers

Data Until I Die!

Data for Life :)

Paul Turley's SQL Server BI Blog

sharing my experiences with the Microsoft data platform, SQL Server BI, Data Modeling, SSAS Design, Power Pivot, Power BI, SSRS Advanced Design, Power BI, Dashboards & Visualization since 2009

Grant Fritchey

Intimidating Databases and Code

Madhivanan's SQL blog

A modern business theme

Alessandro Alpi's Blog

DevOps could be the disease you die with, but don’t die of.

Paul te Braak

Business Intelligence Blog

Sql Insane Asylum (A Blog by Pat Wright)

Information about SQL (PostgreSQL & SQL Server) from the Asylum.

Gareth's Blog

A blog about Life, SQL & Everything ...