从命名空间调用函数

从命名空间调用函数

本文介绍了从命名空间调用函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试更改 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?

具体例子:

如何访问 copula::rmvdc 中使用的 asCall() 函数?

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

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

所以 as.Call() 存在于 copula 包中,但是如何访问它呢?

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'

推荐答案

试试这个:

copula:::asCall

这是之前在 R-help 上的回答.该函数未在包命名空间中导出,因此您需要改用 ::: 运算符.当函数不用于一般用途时(例如,在这种情况下您不需要记录它们),通常不会导出函数.

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).

这篇关于从命名空间调用函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!