在 NLP R 包中找不到 ngrams() 函数

ngrams() function not found in NLP R package

这是直接来自 NLP.pdf 的代码。我输入了 RStudio 控制台。我很纳闷。

library("NLP")
library("tm")
s <- "The quick brown fox jumps over the lazy dog"
w <- strsplit(s, " ", fixed = TRUE)[[1L]]
ngrams(w, 3L)

Error: could not find function "ngrams"

ngrams 功能是在 0.1-7 版本中添加的。确保您至少安装了该版本的软件包。您可以在 运行 library(NLP) 之后查看 sessionInfo() 来检查您 运行ning 是哪个版本。如果您的版本已过期,您可以使用 update.packages() 更新您的本地包。

通常最好查看安装包中包含的文档,而不是单独的 PDF 文件。您可以使用 help(package="NLP") 调出软件包的帮助。这将限制该功能不在您安装的版本中。