我正在尝试R中的reticulate package从python
呼叫RStudio
。这是tutorial。
当我执行以下python chunk
时。它可以正常工作并在rmarkdown
中显示结果:
from __future__ import absolute_import
from __future__ import division, print_function, unicode_literals
from sumy.parsers.html import HtmlParser
from sumy.parsers.plaintext import PlaintextParser
from sumy.nlp.tokenizers import Tokenizer
from sumy.summarizers.lsa import LsaSummarizer as Summarizer
from sumy.nlp.stemmers import Stemmer
from sumy.utils import get_stop_words
LANGUAGE = "czech"
SENTENCES_COUNT = 10
url = "http://www.zsstritezuct.estranky.cz/clanky/predmety/cteni/jak-naucit-dite-spravne-cist.html"
parser = HtmlParser.from_url(url, Tokenizer(LANGUAGE))
# or for plain text files
# parser = PlaintextParser.from_file("document.txt", Tokenizer(LANGUAGE))
stemmer = Stemmer(LANGUAGE)
summarizer = Summarizer(stemmer)
summarizer.stop_words = get_stop_words(LANGUAGE)
sentences = []
for sentence in summarizer(parser.document, SENTENCES_COUNT):
print(sentence)
sentences.append(sentence)
我无法在R代码中访问sentences[]
:
py$sentences
Error in py_get_attr_impl(x, name, silent) : AttributeError: module '__main__' has no attribute 'sentences'
但是,当我使用python
方法在repl_python()
中运行所有python代码时。我可以访问py$sentences
的{{1}}。
问题是,是否有更好的方法,为什么我可能无法使用list
将正常输出用于R对象?我不想返回reticulate::py_to_r(py$sentences)
,我想将list
转换为sentences[]
或R vector
。我看过here,here和here,但没有用。我已经将网状软件包更新为开发版本,但仍然没有用。