Skip to main content
  1. Posts/

String processing in R

·119 words·1 min·
Tim Liu
Author
Tim Liu
Personalizing medicine · MB BChir & Information/Bioengineering BA (Cambridge) · genetics & genomics, machine learning, digital healthcare

Case
#

snakecase::to_any_case() help to fix the case of words - useful for converting between presentation data and processing data.

Regex
#

The regex in R is not 100% perl flavored. For example, escape character is \\ instead of \.

I love the [{rev}](https://github.com/kevinushey/rex package). The most salient point that this package solves is on the interpretation of regex.

When not to use regex
#

Not all strings are interpreted as a regex. Sometimes, one needs to opt-in via a parameter in the function. I have also found myself mistakenly using regex with the ==, which expects a pure string.

{stringr}
#

general pattern: str_x(string, pattern). (I sometimes forgot that it is the variable to be put in front).