textclean
textclean copied to clipboard
Feature request
trafficstars
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
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.