Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Knitr提供与RStudio不同的结果_R_Knitr_Rweka - Fatal编程技术网

Knitr提供与RStudio不同的结果

Knitr提供与RStudio不同的结果,r,knitr,rweka,R,Knitr,Rweka,我正在使用“tm”和“RWeka”进行一些初始文本挖掘,使用Knitr进行再现 我试图获得基于两个文本文件的语料库的术语文档矩阵,当我在RStudio中运行代码和将其编入HTML文件时,该过程会产生不同的结果: 。。。当我尝试其他文档输出PDF和Word输出时: 同意RStudio 而且,我需要一个HTML输出 你知道会发生什么吗 这是.Rmd代码 --- title: "test" author: "me" output: word_document --- ```{r init, echo

我正在使用“tm”和“RWeka”进行一些初始文本挖掘,使用Knitr进行再现

我试图获得基于两个文本文件的语料库的术语文档矩阵,当我在RStudio中运行代码和将其编入HTML文件时,该过程会产生不同的结果:

。。。当我尝试其他文档输出PDF和Word输出时:

同意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
---
标题:“测试”
作者:“我”
输出:word\u文档
---
```{r init,echo=FALSE,warning=FALSE,cache=TRUE,message=FALSE}
图书馆(knitr)
图书馆(tm)
图书馆(SnowballC)
图书馆(鲁韦卡)
setwd(“~”)
选项(mc.cores=1)#并行处理的一些问题
```
```{r 1-gram-test,echo=FALSE,eval=TRUE,cache=TRUE}

doc1我遇到了类似的问题,然后意识到我正在使用选项
cache=TRUE
缓存我的
knitr
块(您似乎也设置了这个选项)

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


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

这有什么不同?是否存在任何警告或错误?如果在控制台中多次运行同一代码,结果是否一致?完全没有警告或错误(PDF、HTML或RStudio)。控制台上的结果一致…您解决过这个问题吗?最令人沮丧的是,我得到了类似的结果