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

Feature request #53

Open
snvv opened this issue Mar 23, 2020 · 1 comment
Open

Feature request #53

snvv opened this issue Mar 23, 2020 · 1 comment

Comments

@snvv
Copy link

snvv commented Mar 23, 2020

I don’t know if it is possible to include, in your fantastic package, replacements for percentage numbers (i.e. +10% -> positive percentage increase, +20% very positive percentage increase, etc.)

Ideally, the number will be defined by the user.

Regards
Sotiris

@trinker
Copy link
Owner

trinker commented Oct 8, 2021

You have the tools to do this already with something like:

txt <- "+10% from last quarter, +20% the following and then -35% close"


swap_percent_change <- function(x, breaks = c(-1, seq(10, 30, by=10), Inf), 
    labels = c('low', 'moderately', 'very', 'extremely'), ...){

    n <- substring(x, 1, 1)
    m <- as.numeric(substring(x, 2, nchar(x) - 1))
    direction <- ifelse(n == '+', 'positive', 'negative')
    direction2 <- ifelse(n == '+', 'increase', 'decrease')
    magnitude <- cut(m, breaks, labels = labels)
    glue::glue('<{{magnitude} {direction} percentage {direction2}}>')

}


fgsub(txt, '[+-][0-9.]+%', swap_percent_change)

## "<{magnitude} positive percentage increase}> from last quarter, <{magnitude} positive percentage increase}> the following and then <{magnitude} negative percentage decrease}> close"

I'm not sure if there'd be enough demand to include this in the package. I'll leave this open and see if it garners interest.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants