We at STATWORX work a lot with R and we often use the same little helper functions within our projects. These functions ease our daily work life by reducing repetitive code parts or by creating overviews of our projects. At first, there was no plan to make a package, but soon I realised, that it will be much easier to share and improve those functions, if they are within a package. Up till the 24th December I will present one function each day from
helfRlein. So, on the 23th day of Christmas my true love gave to me…
What can it do?
This little helper adds functionality to the base R function
strsplit – hence the same name! It is now possible to split
between a given delimiter. In the case of
between you need to specify two delimiters.
An earlier version of this function can be found in this blog post, where I describe the used regular expressions, if you are interested.
How to use it?
Here is a little example on how to use the new
text <- c("This sentence should be split between should and be.") strsplit(x = text, split = " ") strsplit(x = text, split = c("should", " be"), type = "between") strsplit(x = text, split = "be", type = "before")
[]  "This" "sentence" "should" "be" "split" "between" "should"  "and" "be." []  "This sentence should" " be split between should and be." []  "This sentence should " "be split " "between should and "  "be."
Have a merry advent season!