{"id":14068313,"url":"https://github.com/mkearney/chr","last_synced_at":"2025-07-04T18:07:18.366Z","repository":{"id":124078240,"uuid":"115059239","full_name":"mkearney/chr","owner":"mkearney","description":"🔤 Lightweight R package for manipulating [string] characters","archived":false,"fork":false,"pushed_at":"2018-10-18T15:50:59.000Z","size":732,"stargazers_count":17,"open_issues_count":1,"forks_count":2,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-26T05:41:53.492Z","etag":null,"topics":["character","chr","extract","mkearney-r-package","ngram","r","r-package","regex","rstats","string-manipulation","strings","text-processing"],"latest_commit_sha":null,"homepage":"https://chr.mikewk.com","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mkearney.png","metadata":{"files":{"readme":"README.Rmd","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-12-22T00:30:20.000Z","updated_at":"2025-03-22T11:11:49.000Z","dependencies_parsed_at":null,"dependency_job_id":"a249d696-ccd1-4d49-9ecd-6c6216994e46","html_url":"https://github.com/mkearney/chr","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkearney%2Fchr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkearney%2Fchr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkearney%2Fchr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkearney%2Fchr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mkearney","download_url":"https://codeload.github.com/mkearney/chr/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248557844,"owners_count":21124165,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["character","chr","extract","mkearney-r-package","ngram","r","r-package","regex","rstats","string-manipulation","strings","text-processing"],"created_at":"2024-08-13T07:06:05.515Z","updated_at":"2025-04-12T10:51:12.540Z","avatar_url":"https://github.com/mkearney.png","language":"R","funding_links":[],"categories":["R"],"sub_categories":[],"readme":"---\noutput: github_document\n---\n\n```{r setup, include=FALSE}\nknitr::opts_chunk$set(echo = TRUE, collapse = TRUE, comment = \"#\u003e\")\nlibrary(chr)\n```\n\n# chr \u003cimg src=\"man/figures/logo.png\" width=\"160px\" align=\"right\" /\u003e \n\n[![lifecycle](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://www.tidyverse.org/lifecycle/#experimental)\n\nR package for simple string manipulation\n\n## Description\n\nClean, wrangle, and parse character [string] vectors using base exclusively base\nR functions.\n\n## Install\n\n```{r install, eval=FALSE}\n## install devtools is not alreasy installed\nif (!requireNamespace(\"devtools\", quietly = TRUE)) {\n  install.packages(\"devtools\")\n}\n\n## install chr from github\ndevtools::install_github(\"mkearney/chr\")\n\n## load chr\nlibrary(chr)\n```\n\n## Usage\n\n### Detect\n\n**Detect** text patterns (an easy-to-use wrapper for `base::grep()` and `base::grepl()`).\n\n```{r grep}\n## return logical vector\nchr_detect(letters, \"a|b|c|x|y|z\")\n\n## return inverted logical values\nchr_detect(letters, \"a|b|c|x|y|z\", invert = TRUE)\n\n## return matching positions\nchr_detect(letters, \"a|b|c|x|y|z\", which = TRUE)\n\n## return inverted matching positions\nchr_detect(letters, \"a|b|c|x|y|z\", which = TRUE, invert = TRUE)\n\n## return matching values\nchr_detect(letters, \"a|b|c|x|y|z\", value = TRUE)\n\n## return inverted matching values\nchr_detect(letters, \"a|b|c|x|y|z\", value = TRUE, invert = TRUE)\n```\n\n### Extract\n\n**Extract** text patterns.\n\n```{r extract}\n## some text strings\nx \u003c- c(\"this one is @there\n  has #MultipleLines https://github.com and \n  http://twitter.com @twitter\",\n  \"this @one #istotally their and \n  some non-ascii symbols: \\u00BF \\u037E\", \n  \"this one is they're https://github.com\", \n  \"this one #HasHashtags #afew #ofthem\", \n  \"and more @kearneymw at https://mikew.com\")\n\n## extract all URLS\nchr_extract_links(x)\n\n## extract all hashtags\nchr_extract_hashtags(x)\n\n## extract mentions\nchr_extract_mentions(x)\n```\n\n### Count\n\n**Count** number of matches.\n\n```{r count}\n## extract all there/their/they're\nchr_count(x, \"there|their|they\\\\S?re\", ignore.case = TRUE)\n```\n\n### Remove\n\n**Remove** text patterns.\n\n```{r remove}\n## remove URLS\nchr_remove_links(x)\n\n## string together functions with magrittr pipe\nlibrary(magrittr)\n\n## remove mentions and extra [white] spaces\nchr_remove_mentions(x) %\u003e%\n  chr_remove_ws()\n\n## remove hashtags\nchr_remove_hashtags(x)\n\n## remove hashtags, line breaks, and extra spaces\nx %\u003e%\n  chr_remove_hashtags() %\u003e%\n  chr_remove_linebreaks() %\u003e%\n  chr_remove_ws()\n\n## remove links and extract words\nx %\u003e%\n  chr_remove_links() %\u003e%\n  chr_remove_mentions() %\u003e%\n  chr_extract_words()\n```\n\n### Replace\n\n**Replace** text with string.\n\n```{r replace}\n## replace their with they're\nchr_replace(x, \"their\", \"they're\", ignore.case = TRUE)\n```\n\nASCII functions currently *in progress*. For example, replace non-ASCII symbols\nwith similar ASCII characters (*work in progress*).\n\n```{r ascii}\n## ascii version\nchr_replace_nonascii(x)\n```\n\n\n### n-grams\n\nCreate **ngram**s at the character-level.\n\n```{r ngrams}\n## character vector\nx \u003c- c(\"Acme Pizza, Inc.\", \"Tom's Sports Equipment, LLC\")\n\n## 2 char level ngram\nchr_ngram_char(x, n = 2L)\n\n## 3 char level ngram in lower case and stripped of punctation and white space\nchr_ngram_char(x, n = 3L, lower = TRUE, punct = TRUE, space = TRUE)\n```\n\n### Contributions\n\nPlease note that this project is released with a [Contributor Code of Conduct](CODE_OF_CONDUCT.md). By participating in this project you agree to abide by its terms.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmkearney%2Fchr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmkearney%2Fchr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmkearney%2Fchr/lists"}