Search code examples
pythonranacondareticulate

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.

I think the problem is because the python I actually use is installed with Anaconda, and the RStudio don't. I'm using Ubuntu 18.04.

I've have tried, simple test codes, but anything I've tried returns NULL like:

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. Thank you.


Solution

  • Is possible to use reticulate::use_condaenv() as djfinnoy says in the comments, to solve the problem and use the conda enviorement.