本文介绍了R:在自写包中使用 magrittr 管道运算符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我自己写的一个包中使用 magrittr 包中引入的管道运算符 %>% 来链 dplyr 数据转换.magrittrDESCRIPTION 文件中列为 Import.在加载我自己的包并测试使用管道运算符的函数后,我收到以下错误消息:

I would like to use the pipe-operator %>% introduced in the magrittr package in a package I wrote myself to chain dplyr data transformations. magrittr is listed as Import in the DESCRIPTION file. After loading my own package and testing the function which uses the pipe-operator I get the following error message:

函数名错误(参数,:找不到函数%>%"

在函数源代码中将 %>% 更改为 magrittr::%>% 也无济于事,因为无法再构建包.

Changing %>% to magrittr::%>% in the function source code does not help either because the package cannot be built anymore.

推荐答案

如果您在 Depends 中列出了 magrittr,它应该可以正常工作.但是,这是不建议.相反,您将 magrittr 留在 Imports 中,并将以下行添加到 NAMESPACE:

It should have worked correctly if you had magrittr listed in Depends. However, this is not advised. Instead, you leave magrittr in Imports and add the following line to NAMESPACE:

importFrom(magrittr,"%>%")

我建议阅读 编写 R 扩展.第 1.1.3 和 1.5.1 段涵盖了您的问题.

I suggest reading Writing R extensions. Your question is covered in paragraphs 1.1.3 and 1.5.1.

这篇关于R:在自写包中使用 magrittr 管道运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 15:04