2016-03-06 64 views
0

下面的代码在编写装有R内核的ipython笔记本时工作正常。不幸的是,第二个barplot导出为html失败(两者都嵌入了jupyter选项和手动使用nbconvert)。在Jupyter上使用R内核将笔记本导出到html时出现问题

library(NLP) 
library(tm) 

# here I used the EBook of Ulysses, by James Joyce, but any text file can fit 
# the text is available here: https://www.gutenberg.org/cache/epub/4300/pg4300.txt 
book <- readLines("pg4300.txt", encoding="UTF-8") 
corpus <- Corpus(VectorSource(book)) 
corpus <- tm_map(corpus, content_transformer(tolower)) 
corpus <- tm_map(corpus, removeNumbers) 
corpus <- tm_map(corpus, removePunctuation) 
dtm <- TermDocumentMatrix(corpus) 
m <- as.matrix(dtm) 

freq <- rowSums(m) 
freq.sorted <- sort(freq, decreasing=TRUE) 

# first barplot with stop words (ok for both notebook and export) 
barplot(freq.sorted[1:50], xlab="Word", ylab="Frequency", las=2) 

corpus.sw <- tm_map(corpus, removeWords, stopwords('english')) 
dtm.sw <- TermDocumentMatrix(corpus.sw) 
m.sw <- as.matrix(dtm.sw) 
freq.sw <- rowSums(m.sw) 
freq.sw.sorted <- sort(freq.sw, decreasing=TRUE) 

# second barplot without stop words (ok on ipython notebook but fail when exporting) 
barplot(freq.sw.sorted[1:50], xlab="Word", ylab="Frequency", las=2) 

什么是很奇怪的,这是第一barplot良好出口,而不是第二个,而这个过程是完全一样的(出50点强的话)。

这里是我的配置:

  • MacOSX的10.11.2埃尔卡皮坦
  • jupyter 4.0.6
  • IPython中4.0.1
  • [R版本3.2.2

谢谢你,

Julien

+0

我可以导出,但第二个情节已经乱码X标签。我认为原因是nbconvert不使用iframes svg绘图,就像在笔记本本身中完成一样。 –

+0

现在在https://github.com/jupyter/nbconvert/issues/290中跟踪此问题 –

回答

相关问题