Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add vignette for complex phrases #39

Open
rjake opened this issue Jan 25, 2021 · 0 comments
Open

Add vignette for complex phrases #39

rjake opened this issue Jan 25, 2021 · 0 comments
Assignees
Labels
documentation Improvements or additions to documentation

Comments

@rjake
Copy link
Owner

rjake commented Jan 25, 2021

Add headlines together (give credit to glue)

headliner::headline(1, 2) + headliner::headline(3,4)
# decrease of 1 (1 vs. 2) decrease of 1 (3 vs. 4)

Multiple trend_terms() and plural_phrasing()

headline(
  35, 30, 
  headline = 
    "We had {article_trend[1]} {trend[1]} of {delta} {people[1]}.
    That is {delta} {trend[2]} {people[2]} \\
    than the same time last year ({orig_values}).",
  trend_phrases = 
    trend_terms(
      more = c("increase", "more"),
      less = c("decrease", "less")
    ),
  plural_phrases = 
    list(
      people = plural_phrasing(
        single = c("person", "employee"), 
        multi = c("people", "employees")
      )
    )
)

#> We had an increase of 5 people.
#> That is 5 more employees than the same time last year (35 vs. 30).

Create list of headlines

headline_counts <- function(...) {
  headline(
    ..., 
    headline = "{delta} {trend} {people}",
    trend_phrases = trend_terms("more", "less"),
    plural_phrases = list(people = plural_phrasing("person", "people"))
  )
}

headline_percents <- function(...) {
  headline(
    ..., 
    headline = "{delta_p}% {trend}",
    trend_phrases = trend_terms("higher", "lower")
  )
}

headline(30, 40)
# decrease of 10 (30 vs. 40)

headline_counts(30, 40)
# 10 less people

headline_percents(30, 40)
# 25% lower


headline_types <- 
  list(
    simple = headline, 
    n = headline_counts, 
    pct = headline_percents
  )


make_headlines <- function(compare, reference, headline_methods) {
  map(
    .x = headline_methods,
    .f = ~(.x(compare, reference))
  )
}

headline_employees <- make_headlines(30, 35, headline_types)

headline_employees$simple
# decrease of 5 (30 vs. 35)

headline_employees$n
# 5 less people 

headline_employees$pct
# 14.3% lower

Capitalize words

headline(
  x = 12,
  y = 8,
  headline = "{cap(art( trend ))} of {delta_p}%",
  cap = stringr::str_to_sentence,
  art = add_article
)
# "An increase of 50%"
@rjake rjake self-assigned this Jan 25, 2021
@rjake rjake added the documentation Improvements or additions to documentation label Jan 25, 2021
@rjake rjake changed the title Add vignette for complex phrases Fix logic for complex phrases Feb 7, 2021
@rjake rjake changed the title Fix logic for complex phrases Add vignette for complex phrases Feb 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

1 participant