Given a function, how do you determine which namespace it has come from?
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).
There is a getNamespace
function but seems to only accept package names rather than function names.
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.
Namespaces in C++ You only need to prefix the function you wish to call with namespace_name:: -- similar to how you would call a static member function of a class. Another convenience of namespaces is that they allow you to use the same function name, when it makes sense to do so, to perform multiple different actions.
A namespace is a declarative region that provides a scope to the identifiers (the names of types, functions, variables, etc) inside it. Namespaces are used to organize code into logical groups and to prevent name collisions that can occur especially when your code base includes multiple libraries.
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"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With