NLG with narrator

Getting started with narrator package
Author

Denis Abdullin

Published

July 23, 2023

# install.packages("devtools")
devtools::install_github("denisabd/narrator")

Basics

The core idea behind narrator is using glue package template engine.

measure <- "Profit"
profit <- "368.2 M"
dimension <- "Category"
level <- "Research"


glue::glue("Overall {measure} for {level} {dimension} is equal to {profit}.")
Overall Profit for Research Category is equal to 368.2 M.
library(narrator)
library(dplyr)
library(knitr)

sales %>%
  narrate_descriptive(measure = "Sales",
               dimensions = c("Region", "Product"))
$`Total Sales`
Total Sales across all Regions is 38790478.4.

$`Region by Sales`
Outlying Regions by Sales are NA (18079736.4, 46.6 %) and EMEA (13555412.7, 34.9 %).

$`NA by Product`
In NA, significant Products by Sales are Food & Beverage (7392821, 40.9 %) and Electronics (3789132.7, 21 %).

$`EMEA by Product`
In EMEA, significant Products by Sales are Food & Beverage (5265113.2, 38.8 %) and Electronics (3182803.4, 23.5 %).

$`Product by Sales`
Outlying Products by Sales are Food & Beverage (15543469.7, 40.1 %) and Electronics (8608962.8, 22.2 %).