knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "README-"
)

bhappyr

R package: Amusing Sentences Generator. Includes addin.

Generates amusing feedback to lighten the mood of statisticians. Contains addin as well as sentence generator functions.

Pass new structures and word lists to generate unique sentences.

Rate sentences on a given question and rating scale. Simulate user ratings.

By Ludvig R. Olsen,
Cognitive Science, Aarhus University.
Started in March, 2017

Contact at: r-pkgs@ludvigolsen.dk

Main functions:

Installation

install.packages("devtools")

devtools::install_github("LudvigOlsen/bhappyr")

Use addin

Examples

Addin: generateHappyFeedback()

Quickly generate a (hopefully) amusing sentence.

# Attach packages
library(bhappyr)

generateHappyFeedback()
generateHappyFeedback()
generateHappyFeedback()

Generate sentences with more control

Pass new structures and word lists and turn off internal structures and word lists.

# Attach packages
library(bhappyr)
library(dplyr) # %>% 
library(knitr) # kable()

# Create structures
st <- c("[salutation]! You are [positive_adj] today! ;)",
        "You [positive_vb_past] that code! [positive_adj]!")

# Create list of word lists
wl <- list("salutation" = c("Sir", "Mother", "Dear", "Friend"),
           "positive_adj" = c("beautiful", "bright", "smart"),
           "positive_vb_past" = c("accomplished","played", "modified"))

## Example 1
# Using internal structures + word lists

# Generate 1 sentence
generate_sentence() %>% 
  kable()

## Example 2
# Providing structures
# and not using internal structures

# Generate 2 sentences
generate_sentence(n = 2, structures = st,
                  int_structures = FALSE) %>% 
  kable()

## Example 3
# Providing word_lists and structures
# and not using internal word_lists and structures

# Generate 3 sentences
generate_sentence(n = 3, structures = st,
                  word_lists = wl,
                  int_structures = FALSE,
                  int_word_lists = FALSE) %>% 
  kable()

Generate and rate sentences

Generate one or more sentences and ask user to rate them in the console.

Pass question, rating scale, and min/max rating labels.

Is able to randomize rating scales - either once or for every sentence. Randomize both min. and max. scale values, or only one of them.

Allows use of word types in max/min rating labels. Find a new word once or for every sentence.

# Attach packages
library(bhappyr)
library(dplyr) # %>% 
library(knitr) # kable()

# Notice: The argument 'simulate' is set to TRUE
# as the function is elsewise interactive, i.e.
# it is waiting for user input.
# Remove or set to FALSE when running as experiment!

# Example 1
# Generate 1 sentence and rate it.
rate_sentence(n=1, simulate = TRUE) %>% 
  kable()

# Example 2
# Generate 2 sentences and rate them.
# Randomize scale max value on each run.
# Set limits of scale, so max value can be
# maximum 100
rate_sentence(n=2, rscale = c(1,'random'),
              rscale_limits = c(1,100),
              change_rscale = TRUE,
              simulate = TRUE) %>% 
  kable()

# Example 3
# Generate 3 sentences and rate them.
# Use random max_rating label on each run.
rate_sentence(n=3, max_rating = "[superb(upper)]",
              change_label = TRUE,
              simulate = TRUE) %>% 
  kable()


LudvigOlsen/bhappyr documentation built on May 7, 2019, 2:02 p.m.