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
我可以導出,但第二個情節已經亂碼X標籤。我認爲原因是nbconvert不使用iframes svg繪圖,就像在筆記本本身中完成一樣。 –
現在在https://github.com/jupyter/nbconvert/issues/290中跟蹤此問題 –