gpt4 book ai didi

r - Knitr 提供与 RStudio 不同的结果

转载 作者:行者123 更新时间:2023-12-04 20:35:43 24 4
gpt4 key购买 nike

我正在使用 Knitr 使用 'tm' 和 'RWeka' 进行一些初始文本挖掘以实现可重复性。

我试图为基于两个文本文件的语料库获取术语文档矩阵,当我在 RStudio 中运行代码和将其编织成 HTML 文件时,该过程有不同的结果:HTML file

...当我尝试其他文档输出 PDF 和 Word 输出时:PDF and Word outputs

同意 RStudio。

而且,我需要一个 HTML 输出....

知道会发生什么吗?

这是.Rmd代码

---
title: "test"
author: "me"
output: word_document
---

```{r init, echo=FALSE, warning=FALSE, cache=TRUE, message=FALSE}
library(knitr)
library(tm)
library(SnowballC)
library(RWeka)
setwd("~")
options(mc.cores=1) # some problems with parallel processing
```
```{r 1-gram-test, echo=FALSE, eval=TRUE,cache=TRUE}

doc1 <- c("en un lugar de la mancha de cuyo nombre no quiero acordarme habitaba un hidalgo de los de adarga antigual, rocín flaco y galgo corredor")
doc2 <- c("había una vez un barquito chiquitito, que no sabía, que no sabía, que no sabía navegar... pasaron un dos tres cuatro cinco seis semanas y el barquito navegó.")
docs <- c(doc1, doc2)
es <- Corpus(VectorSource(docs),
readerControl = list(reader = readPlain,
language = "ES-es", load = TRUE))
es
# convert to plain text
es1 <- tm_map(es, PlainTextDocument)

monogramtok <- function(x) {
RWeka::NGramTokenizer(x, RWeka::Weka_control(min = 1, max = 1))
}

es_tdm1 <- TermDocumentMatrix(es1)

esmono_tdm1 <- TermDocumentMatrix(es1,
control = list(tokenize = monogramtok,
wordLengths = c(1, Inf))) #,

printf("es_tdm1")
es_tdm1

printf("esmono_tdm1")
esmono_tdm1

``

sessionInfo() R version 3.2.3 (2015-12-10) Platform: x86_64-apple-darwin13.4.0 (64-bit) Running under: OS X 10.11.4 (El Capitan)

locale: [3] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages: [3] stats graphics grDevices utils datasets methods base

other attached packages: [3] R.utils_2.2.0 R.oo_1.20.0 R.methodsS3_1.7.1 dplyr_0.4.3 xtable_1.8-0
[6] pander_0.6.0 RWeka_0.4-24 SnowballC_0.5.1 tm_0.6-2 NLP_0.1-9
[11] knitr_1.12.3

最佳答案

我遇到了类似的问题,然后意识到我正在缓存我的 knitr带有选项 cache=TRUE 的块(因为您似乎也已设置)。

如果缓存的块有副作用或依赖于外部资源,这可能会导致一些非常微妙的错误。

当我禁用缓存时,我的再现性问题就消失了。

关于r - Knitr 提供与 RStudio 不同的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36298591/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com