0

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.

  • What does `reticulate::py_config()` return, is it the python directory you're expecting? I had some trouble with this myself, managed to resolve it by pointing reticulate to a different python installation: `reticulate::use_python("/path/to/desired_python")` – djfinnoy Apr 02 '19 at 19:36
  • The output was the anaconda path where I have it installed (/home/alejandro/anaconda3/bin/python), anyway I have specified with `py_config` and the Error changed. Now it appears **Error in py_get_attr_impl(x, name, silent) : AttributeError: module '__main__' has no attribute 'lista'** , when clearly lista is defined. Thank you again. – mantequilla Apr 02 '19 at 20:14
  • Have you tried setting `reticulate::use_condaenv()`? – djfinnoy Apr 07 '19 at 17:26
  • That works on me, thanks :) – mantequilla May 08 '19 at 07:51

1 Answers1

0

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