4

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
ssm
  • 620
  • 6
  • 24

1 Answers1

6

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}) 
unutbu
  • 842,883
  • 184
  • 1,785
  • 1,677
  • 2
    This also works for keyword arguments that have a dot in their name in the R function –  Jan 19 '19 at 01:40