1

I've been looking around for an answer on this for a while but I haven't found any answers. I'm more familiar with R than with python, and I would prefer to use the python package of my company in RStudio rather than Jupyter Notebook. That's why I looked around a bit and found the reticulate package for R to interface R with Python. I've been able to import the company package and call help for python classes of that package ex:

py_help(dev$Report)

Everything works fine. However, when I try to use the Report class as follows

py_run_string('report = Report.from_csv(x)')

python returns this error

NameError: name 'Report' is not defined

When I source a python script

source_python("file_path/script.py")

It gives me the same error. I got a bit more creative then and tried something like this

report <- Report$`from_csv`(x)

This returns another error

Error: object 'Report' not found

I also tried this using repl_python(), but nothing works. I'm using the same conda environment as I would in Jupyter (where everything works fine) and it's also the same python version that is used. I'm confused by the fact that the package is loaded and I'm able to call help about this package. My hope is that I'm doing something wrong in reticulate or someone who had a similar problem can point me to a solution. Otherwise, I will have to stick to Jupyter. Unfortunately, I cannot share any more information about the companies package itself for obvious reasons. I still hope someone can at least point me in the right direction here.

PhilBo
  • 35
  • 5
  • 1
    did you import the package first? For example, `py_run_string("import pandas")`? Check my post on this https://stackoverflow.com/questions/65291603/error-when-trying-to-use-python-gekko-in-r-via-reticulate-package/65300063#65300063 – Irfaan Feb 18 '21 at 17:17
  • Wow, thank you! That was indeed the problem. I had only used the `import()` function that reticulate provides. I didn’t realize that this wouldn’t also import everything in the Python environment! Everything is working now! Thanks for your help. – PhilBo Feb 19 '21 at 01:22

0 Answers0