无法将在python中创建的数组访问到r

时间:2018-11-29 17:26:44

标签: python r rstudio reticulate

我正在尝试R中的reticulate packagepython呼叫RStudio。这是tutorial

当我执行以下python chunk时。它可以正常工作并在rmarkdown中显示结果:

(首先通过在终端中运行以下命令来安装文本摘要python库:pip install git + git://github.com/miso-belica/sumy.git)

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。我看过hereherehere,但没有用。我已经将网状软件包更新为开发版本,但仍然没有用。

0 个答案:

没有答案