使用rpy2访问包含点的圆点的函数(例如,“As.Vector”)

StackOverflow https://stackoverflow.com/questions/6032060

  •  14-11-2019
  •  | 
  •  

我正在尝试使用rpy2从Python中访问“AS.Vector”r函数。为了简单起见,我们想说,我想用rpy2(r码)做一些简单的事情:

x <- as.vector(c(1, 2, 3))
.

由于“as.vector”包含一个名称的点,它不可直接作为rpy2.robjects.r 的成员可用

根据文档,RPY2由下划线替换点数,用于命名功能参数,但它似乎没有为函数名称本身工作。我试过了,例如。“AS_Vector”,“Asvector”无济于。

任何想法?

有帮助吗?

解决方案

Get a reference to the function using the rpy2.robjects.r interface.

So, you could do something like:

as_vector = robjects.r("as.vector")
vect = as_vector(r_vect)

其他提示

According to the documentation, rpy2 does not replace dots by underscores when using 'rpy2.robjects.r'.

You may want to consider the use of 'importr()'

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top