如何确定函数的命名空间? [英] How do you determine the namespace of a function?
问题描述
给定一个函数,如何确定它来自哪个命名空间?
Given a function, how do you determine which namespace it has come from?
例如,如果我在命令提示符下键入 mean.default
,则输出包括它位于基本包中的事实.我希望能够执行 getNamespace(mean.default)
之类的操作并让它返回base"(或实际的基本环境).
For example, if I type mean.default
at the command prompt, the output includes the fact that it is in the base package. I want to be able to do something like getNamespace(mean.default)
and have it return "base" (or the actual base environment).
有一个 getNamespace
函数,但似乎只接受包名而不是函数名.
There is a getNamespace
function but seems to only accept package names rather than function names.
print.function
使用内部代码来检索命名空间.我在 src/main/print.c
中浏览了 do_printfunction
但后来放弃了.
print.function
uses internal code to retrieve the namespace. I got as far as browsing do_printfunction
in src/main/print.c
but then gave up.
推荐答案
我最近了解到 find()
似乎就是这样做的.
I very recently learned about find()
which seems to do just this.
R> find("ls")
[1] "package:base"
R> find("na.locf")
[1] "package:zoo"
这篇关于如何确定函数的命名空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!