I am developing a routine to automatically define several corpora in quanteda. I have several parameters controlling the script and one of them is the name of the corpus that will be generated. I can easily create a corpus programmatically with the function assign() but I completely fail to add any docvars to it.
Once I define the corpus, I usually invoke it throughout the code with the function get(). I have been using this approach quite extensively with success. For some reason, the function docvars() does not seem to accept an object invoked with get().
Please, have a look at the simple code below where I define the corpus and then try to associate a docvar to it.
library(quanteda)
#> Package version: 2.1.2
#> Parallel computing: 2 of 16 threads used.
#> See https://quanteda.io for tutorials and examples.
#> 
#> Attaching package: 'quanteda'
#> The following object is masked from 'package:utils':
#> 
#>     View
nameofthecorpus = "mycorpus"
mytext <- c( "This is a long speech made in 2020",
             "This is another long speech made in 2021")
thedocvars <- c( "2020", "2021" )
assign( nameofthecorpus, corpus( mytext ) )
# I can have a summary of the corpus with get()
summary( get( nameofthecorpus )  )
#> Corpus consisting of 2 documents, showing 2 documents:
#> 
#>   Text Types Tokens Sentences
#>  text1     8      8         1
#>  text2     8      8         1
# Now I wand to add some docvars automatically
# This is where I get stuck
docvars( get( nameofthecorpus ), "year" ) <- thedocvars 
#> Error in docvars(get(nameofthecorpus), "year") <- thedocvars: could not find function "get<-"
Created on 2021-02-17 by the reprex package (v1.0.0)
In principle, I would like to generalize this to multiple docvars at once (e.g., like when they are stored in a data.frame).
Any suggestion?
 
    