R [重复]中具有相同名称的两个函数

时间:2021-12-19 08:34:10

Possible Duplicate:
Masked functions in R
R: Masked Functions
function naming conflicts

可能重复:R R中的掩码函数:掩码函数函数命名冲突

If I have two packages: A and B. Say there is function named funfun in A and there is function named funfun in B too. When I load A and B, how do I use the first funfun?

如果我有两个包:A和B.假设A中有一个名为funfun的函数,B中也有一个名为funfun的函数。当我加载A和B时,如何使用第一个funfun?

require(A)
require(B)

If I want to use funfun in A, how do I write this?

如果我想在A中使用funfun,我该如何写这个?

1 个解决方案

#1


10  

You can explictily refer to a package and function combination like this:

您可以明确地引用这样的包和函数组合:

A::funfun
B::funfun

In unusual circumstances, you may have to refer to functions that are not exported in the namespace, in which case you need to use:

在特殊情况下,您可能必须引用未在命名空间中导出的函数,在这种情况下您需要使用:

A:::funfun
B:::funfun

(But this would be unusual, and since non-exported functions do not form part of the package API, these functions could change without warning in subsequent releases of a package.)

(但这是不寻常的,因为非导出函数不构成软件包API的一部分,所以这些函数可能会在后续版本的软件包中发生更改而不会发出警告。)

#1


10  

You can explictily refer to a package and function combination like this:

您可以明确地引用这样的包和函数组合:

A::funfun
B::funfun

In unusual circumstances, you may have to refer to functions that are not exported in the namespace, in which case you need to use:

在特殊情况下,您可能必须引用未在命名空间中导出的函数,在这种情况下您需要使用:

A:::funfun
B:::funfun

(But this would be unusual, and since non-exported functions do not form part of the package API, these functions could change without warning in subsequent releases of a package.)

(但这是不寻常的,因为非导出函数不构成软件包API的一部分,所以这些函数可能会在后续版本的软件包中发生更改而不会发出警告。)