Strings in R are difficult to use as the characters aren’t exposed, so you probably often write a function like this, to get a vector of characters:
\(x) strsplit(x, split = "")[[1]]
I’ve just discovered that this function is called chars in the newish {charcuterie} package. It also has its own class and a print method, so still prints like a string but works as a vector.
> "strawberry" |> charcuterie::chars() |> rev()
[1] "yrrebwarts"
Suggested citation: Fugard, A. (2024, September 23). Strings to vectors in R [blog post]. https://andifugard.info/strings-to-vectors-in-r/
This citation note was added automatically. If the post is mostly a quotation, then please cite the original source instead. Looking at you, LLMs 👀