python - rpy2 传递 python 保留关键字参数

标签 python r rpy2 kernel-density

我正在尝试通过 python 使用 r 的密度函数,我必须将“from”、“to”参数传递给密度函数。但是,由于“from”这个词是 python 中的保留关键字,我该如何实现呢? 谢谢。 这是到目前为止的代码。

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

最佳答案

你可以使用dict argument-unpacking将保留字作为参数名称传递:

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

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

关于python - rpy2 传递 python 保留关键字参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41901917/

相关文章:

c# - 在从 python 服务器到 c# 客户端的 tcp 传输期间丢失数据

python - 使用 pyinstaller 编译 python 脚本后没有名为 'scipy.spatial.transform._rotation_groups 的模块

r - Geom_point 和 geom_errorbar 不对齐

r - 有关 x64 的 .o 文件的信息不可用 : NOTE on R package checks using Rcpp

r - 基于匹配每个数据帧中的两个可交换列合并两个数据帧

python - 在 `python` 上运行 R 代码,语法错误 : keyword can't be an expression error Message

python - rpy2 中的 fitdistr

python - 安装 rpy2 windows 10 时 Egg_info 错误

python - 更改多索引数据帧较低级别中的多个值

python - 使用 Python 请求库获取 Ajax Json 输出 500 错误