有没有办法从导入的包中排除函数。例如,我几乎使用了所有 dplyr
但最近,他们添加了一个名为 recode
的新功能。它覆盖了我从专有包中获得的函数(我无法对其进行更改)。
有没有办法从命名空间中排除 s3 函数,以便它只能从我的包中看到该函数,而忽略来自 dplyr
的函数.
我知道我们可以轻松地从包中导入一次性函数,但在这种情况下,我希望排除 - 只有一个。
最佳答案
R 3.3.0 或更高版本现在支持 "import all but x,y,z from foo" statements :
\item The \code{import()} namespace directive now accepts an argument \code{except} which names symbols to exclude from the imports. The \code{except} expression should evaluate to a character vector (after substituting symbols for strings). See Writing R Extensions.
我认为这正是您在这里想要的,并且希望大多数人想要谁不打算让 dplyr 破坏 R 附带的 stats 包中的函数,例如
filter
或 lag
.根据后来在评论中的讨论进行编辑:
文件
NAMESPACE
中的示例用法示例每 Section 1.5.1 of WRE如下:import(dplyr, except = c(recode, lag, filter))
关于从导入的包中删除(或排除)一个函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38296071/