R语言中通常使用NULL
值作为默认值。使用Python和RPy2,如何显式提供NULL
参数?
None
不可转换(NotImplementedError
),字符串'NULL'将仅被转换为字符串,并在执行期间导致错误。
以下是使用tsintermittent
包的示例:
import numpy as np
from rpy2.robjects.packages import importr
from rpy2.robjects import numpy2ri
numpy2ri.activate()
tsintermittent = importr('tsintermittent')
crost = tsintermittent.crost
ts = np.random.randint(0,2,50) * np.random.randint(1,10,50)
# implicit ok, default w is NULL
# crost(ts)
# explicit - how to do it?
# RRunTimeError - non numeric argument
crost(ts, w='NULL')
# NotImplementedError
crost(ts, w=None)