I need to locate the first space following each 20 characters in a string and insert a new line instead of this space. I´m using R and the stringr package. So far I managed to add a new line instead of each space using this code:
gsub(" ", "\n", "My very long and very annoying string")
"My\nvery\nlong\nand\nvery\nannoying\nstring"
But I need to do this only for the first space after the 20th, 40th, 60th etc. character. The result should look like this (because very constains the 20th character):
"My very long and very\nannoying string"
How can I solve this?