我在理解與rpy2對象和python對象的映射時遇到了一些麻煩。 我有一個函數(x)返回一個元組對象在Python中,我想映射這個元組對象與R對象列表或向量。 首先,我試圖做到這一點: # return a python tuple into this r object tlist
robjects.r.tlist = get_max_ticks(x)
#Convert list into
tuple in boost以及TR1/C++ 0x爲從函數返回兩個值提供了一個方便(用於函數的作者)方法 - 但是它似乎 T happy();
const auto meaningful_name(happy()); // RVO means no excess copies
但: tuple<T,U> sad();
我們要麼必須交出挑一的能力,簡單地使用功能初始化變量的能力:呼叫者的
假設如下: def MyFunc(a):
if a < 0:
return None
return (a+1, a+2, a+3)
v1, v2, v3 = MyFunc()
# Bad ofcourse, if the result was None
什麼是定義返回一個元組,但能很好地被調用的函數的最佳方式。目前,我可以做到這一點:
r = MyFunc