虽然函数在包中,但“找不到函数”错误

时间:2022-03-21 14:57:58

In R, I'm getting an error "could not find function...". The function is present inside the package. Still when I run the package, getting the error.

在R中,我收到错误“找不到功能......”。该功能存在于包内。仍然在我运行包时,得到错误。

I am getting this error in the ChainLadder package, while running MackChainLadderFunctions.R. For example, the function checktriangle is present inside the package in Chainladder.R. Still R is not able to recognize the function or call the function.

我在运行MackChainLadderFunctions.R时在ChainLadder包中收到此错误。例如,函数checktriangle存在于Chainladder.R中的包中。 Still R无法识别该功能或调用该功能。

1 个解决方案

#1


4  

Two problems here.

这里有两个问题。

  • function names are case-sensitive (checkTriangle, not checktriangle)
  • 函数名称区分大小写(checkTriangle,而不是checktriangle)

  • checkTriangle is not exported from the package (i.e., it's a private function intended for use within the package only), so you need ::: to access it ... try ChainLadder:::checkTriangle.
  • checkTriangle不是从包中导出的(即,它只是一个私有函数,只在包中使用),所以你需要:::来访问它...尝试ChainLadder ::: checkTriangle。

Using private functions is "at your own risk/programmer beware"; private functions are undocumented, may change in future versions, etc.. If you can find a way to do what you need to do with public functions, that is generally preferred.

使用私有功能“由你自己承担风险/程序员要小心”;私有函数没有文档,可能会在将来版本中更改等。如果您可以找到一种方法来执行您需要处理的公共函数,那么这通常是首选。

AFAICT you're running into this problem because you're trying to source() (or cut-and-paste) package code in your R session. This shouldn't happen if you load the package with library("ChainLadder") and use the public functions (if it does, please edit your question to give a little more context about how you're using the package ...)

AFAICT您遇到此问题是因为您尝试在R会话中源()(或剪切并粘贴)包代码。如果您使用库(“ChainLadder”)加载包并使用公共函数(如果它,请编辑您的问题以提供有关您如何使用该包的更多上下文...),这不应该发生。

#1


4  

Two problems here.

这里有两个问题。

  • function names are case-sensitive (checkTriangle, not checktriangle)
  • 函数名称区分大小写(checkTriangle,而不是checktriangle)

  • checkTriangle is not exported from the package (i.e., it's a private function intended for use within the package only), so you need ::: to access it ... try ChainLadder:::checkTriangle.
  • checkTriangle不是从包中导出的(即,它只是一个私有函数,只在包中使用),所以你需要:::来访问它...尝试ChainLadder ::: checkTriangle。

Using private functions is "at your own risk/programmer beware"; private functions are undocumented, may change in future versions, etc.. If you can find a way to do what you need to do with public functions, that is generally preferred.

使用私有功能“由你自己承担风险/程序员要小心”;私有函数没有文档,可能会在将来版本中更改等。如果您可以找到一种方法来执行您需要处理的公共函数,那么这通常是首选。

AFAICT you're running into this problem because you're trying to source() (or cut-and-paste) package code in your R session. This shouldn't happen if you load the package with library("ChainLadder") and use the public functions (if it does, please edit your question to give a little more context about how you're using the package ...)

AFAICT您遇到此问题是因为您尝试在R会话中源()(或剪切并粘贴)包代码。如果您使用库(“ChainLadder”)加载包并使用公共函数(如果它,请编辑您的问题以提供有关您如何使用该包的更多上下文...),这不应该发生。