gpt4 book ai didi

r - 如何从所需的包中调试未导出的函数?

转载 作者:行者123 更新时间:2023-12-04 11:36:21 27 4
gpt4 key购买 nike

我正在使用的包中的一个函数给了我不那么重要的错误。我不知道发生了什么。这个函数由我调用的函数内部调用。像这样的东西:

myres <- the.func(x)

the.func <-function(x){
unexported.func(x)
}

如何调试 unexported.func ?
使用 debug不起作用:
>debug(unexported.func)
Error in debug(undexported.func) : object 'unexported.func' not found

更新:
目前我做嵌套调试如下。但我觉得不方便:
>debug(the.func) # Initiate debugging for the outer function, so I get unexported.func loaded.
>myres <- the.func(x)
Browse[2]>debug(unexported.func) # Now I can call debug with this.

最佳答案

您可以通过 ::: 访问未导出的函数(三冒号)运算符,以包命名空间名称(即包名称)开头。

假设 pkgA 包含未导出的函数 unexported.func() , 我们将在 unexported.func() 上设置调试标志使用:

debug(pkgA:::unexported.func)

如果您不知道将哪个包(因此命名空间)用于给定的未导出函数,您总是可以使用 getAnywhere() 来确定这一点。 .

关于r - 如何从所需的包中调试未导出的函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31254647/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com