Methamortix
Methamortix

Reputation: 110

Replacing texts in quanteda > 3.2.4

while reviewing some old code I realized that texts(x) will be removed in future quanteda releases.

> test <- corpus("Hello, World")
> texts(test) <- gsub("World","world", texts(test))
Warning messages:
1: 'texts.corpus' is deprecated.
Use 'as.character' instead.
See help("Deprecated") 
2: use the '[<-' replacement for a corpus object instead 

However, I am unsure whether I understand the new way to replace texts in a corpus correctly. Is my MWE the correct new way?

test <- corpus(c("Hello, World","Hello, Box"))
test[] <- gsub("Hello","hello", as.character(test))

Thanks and all the best!

Upvotes: 1

Views: 56

Answers (1)

Ken Benoit
Ken Benoit

Reputation: 14902

It's even simpler now:

library("quanteda")
#> Package version: 3.2.5
#> Unicode version: 14.0
#> ICU version: 71.1
#> Parallel computing: 10 of 10 threads used.
#> See https://quanteda.io for tutorials and examples.

test <- corpus(c("Hello, World", "Hello, Box"))
test <- gsub("Hello", "hello", test)
test
#> Corpus consisting of 2 documents.
#> text1 :
#> "hello, World"
#> 
#> text2 :
#> "hello, Box"

Created on 2023-02-20 with reprex v2.0.2

Upvotes: 1

Related Questions