rpy2 passing python reserved keyword arguments

自作多情 提交于 2021-02-07 20:25:57

问题


I am trying to use r's density function through python, and I have to pass the 'from', 'to' arguments to the density functions. However, since the word 'from' is a reserved ketyword in python, how can I achieve this? Thank you. Here is the code so far.

r_density=robjects.r('density')
f_a = robject.FloatVector(a)
r_a = r_density(f_a, bw='SJ', n=1024) ## Here I need to add 'from' and 'to' arguments

回答1:


You can use dict argument-unpacking to pass reserved words as parameter names:

r_a = r_density(f_a, bw='SJ', n=1024, **{'from':1, 'to':3}) 

or

r_a = r_density(f_a, **{'bw':'SJ', 'n':1024, 'from':1, 'to':3}) 


来源:https://stackoverflow.com/questions/41901917/rpy2-passing-python-reserved-keyword-arguments

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!