R:在自写包中使用magrittr管道运算符 [英] R: use magrittr pipe operator in self written package
问题描述
我想将magrittr
包中引入的管道运算符%>%
用于我自己编写的用于链接dplyr
数据转换的包中. magrittr
在DESCRIPTION
文件中被列为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:
函数名错误(参数,:找不到函数%>%"
Error in functionname(parameter, : could not find function "%>%"
在函数源代码中将%>%
更改为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管道运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!