# Quick solution:
::str_squish(
stringr"This text was taken
from a PDF and there are loads of
random page
breaks. Boo!"
)
# No more deleting line breaks by hand!
An easy trick to sort out all the line breaks when copying text from a PDF
Copy-pasting from a PDF into another format (say, Rmd or qmd or Word) and getting fed up with the line breaks? stringr::str_squish() is your friend!
#rstats - also useful for removing manual processes from text editing regardless of the format of the destination document 🤫
The output from a straight copy-paste looks something like this…
This text was taken from a PDF and there are loads of random page breaks. Boo!
See also str_to_sentence and str_to_title for getting rid of all caps, or for… creating a title 🪄
::str_to_sentence(
stringr"THIS IS IN ALL CAPS BUT IT WOULD BE BETTER IF IT WASN'T!"
)
::str_to_sentence(
stringr"Let's make this a title instead"
)
P.S. str_to_sentence() doesn’t currently keep a capital I by default. Has this already been explored and decided against?
::str_to_sentence(
stringr"THIS IS A SENTENCE I'LL NEED TO EDIT MANUALLY. SAD FACE."
)
P.P.S. It will also remove paragraph breaks!
When I posted this online, I had no idea this would be so popular. Clearly, a more common problem than I realised! I couldn’t help thinking there must be some better solutions to my hacky off-label use of str_squish()
…
Here’s a shiny app you can try instead!