I have a function that takes the items in a Python list, puts them through a function in R, and outputs them as a R ListVector. The problem is that I can't find in the documentation how to convert from a ListVector into a regular Python object. Here's my code:
from rpy2.robjects.packages import importr
from rpy2.robjects import r
forecast = importr("forecast")
parallel = importr("multicore")
data = [[1, 2, 3], [4, 5, 6,], [7, 8, 9]]
tuples = tuple(tuple(x) for x in data)
data_list = []
for i in range(0, len(data)):
result1 = "k = as.numeric((list%r))" % (tuples[i],)
data_list.append(result1)
def forecaster(item):
rcode = item
r(rcode)
rcode1 = 'j <- ts(k)'
r(rcode1)
rcode2 = 'p <- parallel(forecast(k, 5, level = c(80,95)))'
r(rcode2)
rcode3 = 'collect(list(p))'
return r(rcode3)
z = [forecaster(x) for x in data_list]
Running z
gives me output like this:
[<ListVector - Python:0x4e5f908 / R:0x4a0fcd8>
[ListVector]
<ListVector - Python:0x4e5f908 / R:0x4a0fcd8>
[ListVector], <ListVector - Python:0x4e5fcf8 / R:0x49f9c48>
...And so on. Could someone please help me figure out how to convert these ListVectors into something I can actually use in Python? Thanks.