简体   繁体   English

Python/rpy2 无法识别 r 代码中的 %>% pipe

[英]Python/rpy2 does not recognize %>% pipe in r code

I have a Python script that will pass dataframes into an R package and get the results.我有一个 Python 脚本,它将数据帧传递到 R package 并获得结果。 The R script works as expected in R studio. R 脚本在 R 工作室中按预期工作。

However I cannot get it to wokr when executing through python/rpy2.但是,当通过 python/rpy2 执行时,我无法将其发送到 wokr。

rpy2.rinterface_lib.embedded.RRuntimeError: Error in ataframe d%>% dplyr::rename(domain = Domain, variable = Variable,  : 
  could not find function "%>%"

Is there a way to get this to work when executing through python?通过 python 执行时有没有办法让它工作? Rewriting the code to not use %>% is working but will require a lot of rewriting that I would prefer to avoid if possible.重写代码以不使用 %>% 是有效的,但需要大量重写,我希望尽可能避免。

I've tried making sure the dplyr library is in every script.我已尝试确保每个脚本中都包含 dplyr 库。 I've confirmed its installed prior to running the python script.在运行 python 脚本之前,我已经确认它已安装。

I have not found any examples of this issue while using rpy2/python.我在使用 rpy2/python 时没有发现任何关于这个问题的例子。

%>% is from the magrittr package. If you have R version 4.1 or later you can use the native |> pipe instead. %>%来自magrittr package。如果你有 R 版本 4.1 或更高版本,你可以使用原生|> pipe 代替。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM