简体   繁体   English

在 R/Python 中使用网状包时出现 NULL 问题

[英]NULL problem while using reticulate package in R/Python

I'm starting to use the reticulate package to be able to use python with R. The code in python actually works, but when trying to get something of the code in R, it returns NULL.我开始使用 reticulate 包以便能够将 python 与 R 一起使用。 python 中的代码实际上可以工作,但是当尝试获取 R 中的某些代码时,它返回 NULL。

I think the problem is because the python I actually use is installed with Anaconda, and the RStudio don't.我认为问题是因为我实际使用的 python 是用 Anaconda 安装的,而 RStudio 没有。 I'm using Ubuntu 18.04.我正在使用 Ubuntu 18.04。

I've have tried, simple test codes, but anything I've tried returns NULL like:我已经尝试过简单的测试代码,但是我尝试过的任何东西都会返回 NULL,例如:

x = 5
py$x #Returns NULL

This how my code actually looks.这就是我的代码的实际外观。

library(reticulate)
def main():
    string1 = "http://ine.es/jaxiT3/files/t/es/xlsx/"
    string2 = ".xlsx?nocab=1"

    lista = list()

    for i in range(2854,2910):
        url = string1 + str(i) + string2

        if i != 2855 + 12 and i != 2855 + 32 and i != 2855 + 42 and i != 2855 + 43:
          lista.append(url)

if __name__ == "__main__":
    main()
py$lista #It returns NULL instead the list

It should returns the list/vector with the URL'S, I know there is a way to do the same code with R, but I wanted to use reticulate.它应该返回带有 URL 的列表/向量,我知道有一种方法可以用 R 执行相同的代码,但我想使用网状。 Thank you.谢谢你。

可以像djfinnoy在评论中所说的那样使用reticulate::use_condaenv()来解决问题并使用 conda 环境。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM