如何在R中获取函数的程序包名称? [英] How to get the package name of a function in R?
问题描述
我正在调试一些代码,我认为在2个程序包中可能具有相同功能的两倍.
I'm debugging some code and I think I might have twice the same function in 2 packages.
我想输出该功能的程序包名称,因为它会由R控制台执行.
I want to output the package name of the function as it would be executed by the R console.
示例:
-
function_package_name(print)
#->基本 -
function_package_name(select)
#-> dplyr
function_package_name(print)
# --> basefunction_package_name(select)
# --> dplyr
我不能简单地使用?select
,因为我认为它链接到两个软件包的选择:dplyr
和MASS
.
I cannot simply use ?select
because I think it links to the choice of 2 packages: dplyr
and MASS
.
我怎么知道我正在使用哪个select
功能?
How can I know which select
function I'm using ?
注意:这不是列出CRAN上所有功能的重复,也不是的名称,从R中的函数名称中找到包名称,所以sos::findFn()
是不可接受的答案!我不是在寻找其他可能像这样的函数,而是在寻找我当前正在使用的函数的包名!
NB : this is NOT a duplicate of list all functions on CRAN, nor of Find the package names from a function name in R, so sos::findFn()
is not an acceptable answer ! I'm not looking for potential other functions named like this one, I'm looking for the package name of the one I'm currently using !
推荐答案
也许甚至最方便,如果您紧随软件包名称之后:
Perhaps even most convenient, if you are just after the package name:
environmentName(environment(select))
优点是,它生成一个字符串而不是一个环境对象.
The advantage is that this produces a string rather than an environment object.
这篇关于如何在R中获取函数的程序包名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!