Using gsub to remove parts from string: it doesn't "stick"?

So I use gsub to remove the instances of \n and - from a corpus, which I've created from a pdf:

cassis1 <- pdf_text("Cassis_2022_1.pdf")
cassis_corpus <- cassis1

gsub("\n|-", "", cassis_corpus)

When I run this, the text is displayed exactly how I want it, with no more \n and -. However, if I run


the text appears as it did before I removed the \n and -.

It seems like gsub makes no permanent change to the corpus. Why is that, and how is one supposed to work with the altered corpus if the changes are not permanent?

Thanks for any tip and help!

You need to assign the result to a variable, e.g.

cassis_corpus <- gsub("\n|-", "", cassis_corpus)

Of course, that makes sense. It's been a while since I used R, this is the result of that. Thank you for still answering this rather basic question :smiley: !

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.