检测或阻止调用不存在的函数的函数定义
Detect or prevent function definition that calls function that does not exist
R 允许以下行为而无需抱怨:
f <- function(x) {
function_that_does_not_exist(x)
}
只有在调用 f()
时才会发生错误。我怎样才能更早地检测到这些错误?
我意识到具有这种后期绑定行为的语言允许您稍后定义缺少的函数,但我很乐意放弃该功能以进行更早的错误检测。
软件包实用程序可能会捕获您想要捕获的内容。特别是如果你在你的函数中添加了一个重要的例子。
我 运行 R CMD check
在一个只有你的函数的包上,它报告:
`* checking R code for possible problems ... NOTE
f: no visible global function definition for
‘function_that_does_not_exist’
* checking Rd files ... WARNING`
然后(我在 Rd 文件中以 f(1) 为例。)
* checking examples ... ERROR
Running examples in ‘fpackage-Ex.R’ failed
The error most likely occurred in:
> ### Name: f
> ### Title: f function
> ### Aliases: f
>
> ### ** Examples
>
> f(1)
Error in f(1) : could not find function
"function_that_does_not_exist"
Execution halted
我不确定这是对您问题的回答。
R 允许以下行为而无需抱怨:
f <- function(x) {
function_that_does_not_exist(x)
}
只有在调用 f()
时才会发生错误。我怎样才能更早地检测到这些错误?
我意识到具有这种后期绑定行为的语言允许您稍后定义缺少的函数,但我很乐意放弃该功能以进行更早的错误检测。
软件包实用程序可能会捕获您想要捕获的内容。特别是如果你在你的函数中添加了一个重要的例子。
我 运行 R CMD check
在一个只有你的函数的包上,它报告:
`* checking R code for possible problems ... NOTE
f: no visible global function definition for
‘function_that_does_not_exist’
* checking Rd files ... WARNING`
然后(我在 Rd 文件中以 f(1) 为例。)
* checking examples ... ERROR
Running examples in ‘fpackage-Ex.R’ failed
The error most likely occurred in:
> ### Name: f
> ### Title: f function
> ### Aliases: f
>
> ### ** Examples
>
> f(1)
Error in f(1) : could not find function
"function_that_does_not_exist"
Execution halted
我不确定这是对您问题的回答。