When using Python's collections.UserList via reticulate, the View function fails in RStudio, see below an example. Can anything fix that? The issue is that if you have multiple objects converted from python in the environment and you click on them you get a cryptic exception.
Python's collections.UserList are wrappers around Python's lists, and can be used for example to customize how do you print a list, or to add functions to apply to all elements, etc.
This is tested in RStudio server 1.3.959.
Python file called 'test_list.py', containing:
import collections
class TestCustomList(collections.UserList):
def __init__(self):
super(TestCustomList, self).__init__()
self.data = [5,6,7]
custom_list = TestCustomList()
print(custom_list)
Executed in RStudio console:
library(reticulate)
py_run_file("test_list.py")
py$custom_list
in_r<-py$custom_list
View(py$custom_list)
Result is:
> library(reticulate)
> py_run_file("test_list.py")
[5, 6, 7]
> py$custom_list
[5, 6, 7]
> in_r<-py$custom_list
> View(py$custom_list)
>
Error in py_get_item_impl(x, key, FALSE) :
TypeError: list indices must be integers or slices, not str
Detailed traceback:
File "/usr/local/lib/python3.7/collections/__init__.py", line 1098, in __getitem__
return self.data[i]
(and clicking on in_r in the environment will result in the same error)