Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling a function from a namespace

Tags:

namespaces

r

I'm trying to alter the functionality of a few commands in a package in R. It's easy enough to see the source of the commands. However the function calls other functions that are in the package namespace. These functions are not exported objects. So how can I access them?

Specific example:

How would I access the asCall() function that is used in copula::rmvdc?

require(copula) copula::rmvdc getAnywhere("asCall") 

so as.Call() exists in the copula package, but how do I access it?

> copula::asCall Error: 'asCall' is not an exported object from 'namespace:copula' 
like image 814
JD Long Avatar asked Jan 29 '10 21:01

JD Long


People also ask

How do you call a function from a namespace?

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.

What is a function namespace?

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.

Can I use namespace std in C++?

The statement using namespace std is generally considered bad practice. The alternative to this statement is to specify the namespace to which the identifier belongs using the scope operator(::) each time we declare a type. Example 1: CPP.

Why should we use using namespace std in C++?

using namespace std; are used. It is because computer needs to know the code for the cout, cin functionalities and it needs to know which namespace they are defined.


1 Answers

Try this:

copula:::asCall 

This was previously answered on R-help. That function was not exported in the package namespace, so you need to use the ::: operator instead. Typically functions are not exported when they are not intended for general usage (e.g. you don't need to document them in this case).

like image 191
Shane Avatar answered Sep 29 '22 05:09

Shane