我最近一直在尝试使用rpy2并将zoo库导入python。 但是,当我运行以下代码集时,我收到以下错误
from rpy2.robjects.packages import importr
r_zoo = importr("zoo")
r_zoo.rollapply(ddf,FUN = r_func.fun1, width = 10, align = "left",by_column = True)
res = super(功能,自我)。致电(* new_args,** new_kwargs) rpy2.rinterface.RRuntimeError:FUN中的错误(data [posns],...):未使用 参数(by_column = TRUE)
等效的r代码是
rollapply(ddf,FUN = r_func.fun1, width = 10, align = "left",by.column = True)
据我所知,当我们使用rpy2.robjects.packages中的importr时,它会自动将Rlang中的'.'
转换为python中的'_'
。
答案 0 :(得分:0)
Two ways to get around that problem:
Use a kwargs
dict
r_zoo.rollapply(ddf,FUN = r_func.fun1, width = 10, align = "left",**{"by.column":True})
Explicitly specify that by_column
is to be translated to by.column
from rpy2.robjects.functions import SignatureTranslatedFunction`
r_zoo.rollapply = SignatureTranslatedFunction(r_zoo.rollapply, init_prm_translate = {'by_column': 'by.column'})