【发布时间】:2021-02-17 19:28:06
【问题描述】:
我正在开发一个例程来自动定义 quanteda 中的几个语料库。我有几个控制脚本的参数,其中之一是将要生成的语料库的名称。我可以使用函数assign() 以编程方式轻松创建语料库,但我完全无法向其中添加任何 docvars。
一旦我定义了语料库,我通常会在整个代码中使用函数get() 调用它。我一直在成功地广泛使用这种方法。出于某种原因,函数docvars() 似乎不接受使用get() 调用的对象。
请看下面我定义语料库的简单代码,然后尝试将 docvar 与其关联。
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<-"
由reprex package (v1.0.0) 于 2021-02-17 创建
原则上,我想一次将其推广到多个 docvar(例如,当它们存储在 data.frame 中时)。
有什么建议吗?
【问题讨论】: