Giter VIP home page Giter VIP logo

tidyfilter's Introduction

tidyfilter

Filter Text Based On List of Words Or Regexes

The use case this was written for is filtering profanity and personally identifiable data in comments made in free text questions in customer satisfaction surveys, for display in Shiny dashboards.

The package uses continuous integration to ensure style, no syntax errors and maintain consistency. Documentation is automated via Roxygenise.

pre-commit

R-CMD-check

Lifecycle: experimental

Installation

devtools::install_github("nhsbsa-data-analytics/tidyfilter")

Usage

Regex based word filter

Use this in dplyr pipelines. It is fast and vectorised. Also, fully configurable, requiring both a list of filter words or regular expressions and a replacement character. Each match will be replaced with the same number of replacement characters as the number of characters in the match.

data <- data.frame(
    w = c("My phone number is 07421 345 678", "Call me on 01234567890")
    x = c("This is some text...", "...containing words."),
    y = c("This is more text...", "...containing something."),
    z = c("This is some more text...", "...containing more words.")
  )

data %>%
  filter_text(
    c("some", "words", "and", "regex", "[0-9]{3,}[\s0-9]*[0-9]"),
    "#",
    w, x, y
  )

#                         w                             x                        y                         z
# 1 My phone number is ############# This is #### text... This is more text...     This is some more text...
# 2 Call me on ###########           ...containing #####. ...containing ####thing. ...containing more words.

Wordlists

Included are 2 word lists for profanity and 1 list of regexes.

  • profane_words_basic.txt: Contains just 4 of the most offensive words.
  • profane_words.txt: Contains nearly 3000 potentially offensive expressions. Beware over-filtering, you will get many false positives!
  • pid_regex: Contains regex to catch dates, phone numbers and emails.
pid_regex <- readLines(system.file("extdata", "pid_regex.txt", package = "tidyfilter"))
profanity <- readLines(system.file("extdata", "profane_words_basic.txt", package = "tidyfilter"))

tidyfilter's People

Contributors

markmc1089 avatar pre-commit-ci[bot] avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.