stringi reverse

Reverse String
Reverse String in R
library(stringi)

reverse <- function(text) {
  stri_reverse(text)
}

This might be considered "cheating" for the Exercism exercise, but it is very commonly used in the context of a larger text-handling task.

The stringi library is regarded as especially strong in handling multiple locales and character sets. Other popular string-handling libraries such as stringr tend to be built on top of stringi.

Code using stri_reverse() is substantially faster than any of the other approaches, scales well to large inputs, and is also versatile enough to handle vectors.

Libraries from the tidyverse package, including stringi, are well designed and performant. Their popularity also means they tend to be well documented, not least in textbooks and video courses. Using them can be a very good idea in non-Exercism contexts.

6th Nov 2024 · Found it useful?