简体   繁体   English

不要在 R 中暴露自己的 package 中导入包的功能

[英]Don't expose functions from imported packages in own package in R

I know this is a real beginners question, and I'd be happy to any pointer to any help.我知道这是一个真正的初学者问题,我很乐意提供任何帮助。 But I found it quite complicated to find some more or less easy to read resource.但我发现找到一些或多或少容易阅读的资源相当复杂。

So the question is that I want to create a package in R.所以问题是我想在R中创建一个package。 Let's say I want to use many functions from the dplyr -package.假设我想使用dplyr中的许多功能。 So I do a @import dplyr at the top of my utils.R where I have many small functions that do some data cleaning etc..所以我在我的 utils.R 顶部做了一个@import dplyr utils.R我有许多小功能可以进行一些数据清理等。

Now when I load all my own functions with devtools::load_all() and start typing the name of my package and :: I get suggestions for all the functions from the dplyr-package as well.现在,当我使用devtools::load_all()加载我自己的所有函数并开始输入我的 package 和::的名称时,我也会从 dplyr-package 中获得所有函数的建议。

What essential aspect am I missing here?我在这里缺少什么重要方面?

You can either import only specific functions from dplyr using the line您可以使用该行仅从dplyr导入特定功能

@importFrom dplyr usefulFunction

which reduces the number of functions that you'll have problems with, or you can remove the import totally, and then refer to functions including the package name, for example dplyr::usefulFunction() whenever you use a function from dplyr . which reduces the number of functions that you'll have problems with, or you can remove the import totally, and then refer to functions including the package name, for example dplyr::usefulFunction() whenever you use a function from dplyr .

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

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